Skip to main content

Python Dynamic Typing Quiz

ยท 6 min read

Progress

Score: 0/20

๐ŸŽฉ Master Quiz: Dynamic Typing

20 Questions. Sticker vs. Box. Strong vs. Weak. Green = Correct, Red = Incorrect.

BeginnerAnalogy

In the "Sticker vs. Box" analogy, what corresponds to Static Typing (Java/C++)?โ€‹

  • **A) The Handheld Label Maker**
  • **B) The Engraved Box ("Shoes Only")**
  • **C) The Pizza**
  • **D) The Shoe**

๐Ÿ’ก Explanationโ€‹

The Engraved Box.

In Static typing, the container (variable) enforces the type. If the box says "Shoes Only", you cannot put a Pizza in it.

BeginnerAnalogy

In the "Sticker vs. Box" analogy, what corresponds to Dynamic Typing (Python)?โ€‹

  • **A) The Handheld Sticker Gun**
  • **B) The Engraved Box**
  • **C) The Factory**
  • **D) The Compiler**

๐Ÿ’ก Explanationโ€‹

The Sticker Gun.

You create a label (variable) and can stick it on anything (Integer, String, etc.). The sticker doesn't care what it's attached to.

CoreType Binding

Where is the "Type" tied to in Python?โ€‹

  • **A) The Variable Name**
  • **B) The Object (Value) in Memory**
  • **C) The Compiler**
  • **D) The File Extension**

๐Ÿ’ก Explanationโ€‹

The Object in Memory.

The variable is just a name tag. The actual object (e.g., the number 5) holds the type information.

IntermediateReassignment

What happens if you run x = 5 then x = "Guru"?โ€‹

  • **A) Allowed (x now points to "Guru")**
  • **B) TypeError (x is an Integer)**
  • **C) Compiler Error**
  • **D) x becomes "5"**

๐Ÿ’ก Explanationโ€‹

Allowed.

You are simply peeling the sticker off the Integer 5 and sticking it onto the String "Guru".

IntermediateType Checking

When does Python check for type errors?โ€‹

  • **A) Compile Time (Before running)**
  • **B) While typing in the IDE**
  • **C) Runtime (When the line executes)**
  • **D) Never**

๐Ÿ’ก Explanationโ€‹

Runtime.

Python checks the type only when the code actually runs. This is why some bugs can hide until that specific line is executed.

BeginnerComparison

When does Java/C++ check for type errors?โ€‹

  • **A) Compile Time (Before running)**
  • **B) Runtime**
  • **C) Only when user inputs data**
  • **D) Never**

๐Ÿ’ก Explanationโ€‹

Compile Time.

The compiler screams at you before you can even run the program if you violate type rules.

AdvancedClassification

Is Python "Strongly Typed" or "Weakly Typed"?โ€‹

  • **A) Strongly Typed**
  • **B) Weakly Typed**
  • **C) Both**
  • **D) Neither**

๐Ÿ’ก Explanationโ€‹

Strongly Typed.

Do not confuse Dynamic with Weak. Python is Strong because it forbids implicit weird conversions like 1 + "1".

AdvancedStrong vs Weak

What happens if you run 1 + "1" in Python?โ€‹

  • **A) "11"**
  • **B) 2**
  • **C) TypeError (Crash)**
  • **D) None**

๐Ÿ’ก Explanationโ€‹

TypeError.

JavaScript (Weak) would give "11". Python (Strong) refuses to mix types implicitly.

ArchitectRisk

What is the biggest risk of Dynamic Typing for Architects?โ€‹

  • **A) Slow compilation**
  • **B) Runtime Errors (Crashes in production)**
  • **C) Hard drive space**
  • **D) Too much boilerplate**

๐Ÿ’ก Explanationโ€‹

Runtime Errors.

If a variable unexpectedly holds None instead of a User object, the script crashes only when that line is hit in production.

ArchitectModern Python

What feature (Python 3.5+) helps mitigate dynamic typing risks?โ€‹

  • **A) Compilers**
  • **B) Strict Mode**
  • **C) Type Hints**
  • **D) Macros**

๐Ÿ’ก Explanationโ€‹

Type Hints.

Example: age: int = 25. This helps IDEs and linters catch errors before you run the code.

AdvancedType Hints

Do Type Hints prevent the code from running if violated?โ€‹

  • **A) Yes, Python stops execution**
  • **B) No, Python ignores them at runtime**
  • **C) Only in Python 3.10+**
  • **D) Yes, if using VS Code**

๐Ÿ’ก Explanationโ€‹

No.

Type hints are for developers and tools (like MyPy). The Python interpreter completely ignores them at runtime.

ConceptDuck Typing

What is the core philosophy of "Duck Typing"?โ€‹

  • **A) "If it walks and quacks like a duck, it's a duck"**
  • **B) "Variables must be declared as Ducks"**
  • **C) "Ducks are immutable"**
  • **D) "Type checking is strict"**

๐Ÿ’ก Explanationโ€‹

If it walks/quacks like a duck...

Python doesn't care about the official class type. It only cares if the object has the methods/behaviors you are trying to use.

IntermediateDuck Typing Example

Does Python care if an object is officially a "File"?โ€‹

  • **A) Yes, it must inherit from File**
  • **B) No, as long as it has a .read() method**
  • **C) Only in standard libraries**
  • **D) Yes, for security reasons**

๐Ÿ’ก Explanationโ€‹

No.

If you create a custom class that has a .read() method, Python will happily treat it like a file.

AdvancedPerformance

Why is Dynamic Typing generally slower than Static Typing?โ€‹

  • **A) Runtime Type Checking overhead**
  • **B) It uses more Hard Drive space**
  • **C) It requires internet access**
  • **D) It isn't slower**

๐Ÿ’ก Explanationโ€‹

Runtime Type Checking overhead.

Python has to ask "What type is this?" every single time you touch a variable, whereas C++ knows the type in advance.

BenefitUse Case

What is a major benefit of Dynamic Typing?โ€‹

  • **A) Compilation speed**
  • **B) Zero runtime errors**
  • **C) Less Boilerplate / Rapid Prototyping**
  • **D) Strict memory management**

๐Ÿ’ก Explanationโ€‹

Less Boilerplate.

You don't need to write int, float, string everywhere. You just write logic, making it faster to write.

IntermediateGeneric Functions

How does Python handle "Generic Functions" (one function for multiple types)?โ€‹

  • **A) You must write overloaded functions**
  • **B) It happens automatically (Natural support)**
  • **C) You need a special library**
  • **D) It is impossible**

๐Ÿ’ก Explanationโ€‹

Natural support.

Since Python doesn't enforce types on arguments, a single function process(data) can handle Lists, Tuples, or JSON without extra code.

SyntaxType Hinting

What is the correct syntax for a Type Hint?โ€‹

  • **A) age: int = 25``**
  • **B) int age = 25``**
  • **C) var age = 25``**
  • **D) age = (int) 25``**

๐Ÿ’ก Explanationโ€‹

age: int = 25

This syntax (introduced in PEP 484) allows you to annotate the expected type.

ArchitectMemory

When x = 5 is reassigned to x = "Guru", what happens to the 5?โ€‹

  • **A) It stays in memory forever**
  • **B) It is overwritten by "Guru"**
  • **C) It is Garbage Collected**
  • **D) It moves to the Stack**

๐Ÿ’ก Explanationโ€‹

It is Garbage Collected.

Since the label x no longer points to 5, the reference count for 5 drops to zero, and the Cleaning Crew deletes it.

IntermediateComparison

Can you reuse a variable name for a different type in Static Typing (Java)?โ€‹

  • **A) Yes**
  • **B) No, Compiler Error**
  • **C) Only for Strings**
  • **D) Only if you cast it**

๐Ÿ’ก Explanationโ€‹

No.

In Static typing, the type is tied to the variable (The Box). You cannot put a String into a variable declared as an Integer.

ArchitectCode Readability

What is the "Mystery Meat" variable problem?โ€‹

  • **A) Not knowing a variable's type without reading context**
  • **B) Variables getting deleted randomly**
  • **C) Variables with long names**
  • **D) Using too many global variables**

๐Ÿ’ก Explanationโ€‹

Not knowing a variable's type.

In large scripts, seeing a variable named data is confusing. Is it a list? A dict? A string? Static typing avoids this ambiguity.

๐ŸŽ‰ Quiz Complete!โ€‹

Your Final Score:

0/20 Novice

Keep practicing to reach Architect level!

  • **โ†บ Retake Quiz**