🎩 Master Quiz: Dynamic Typing
20 Questions. Sticker vs. Box. Strong vs. Weak.
Green = Correct, Red = Incorrect.
In the “Sticker vs. Box” analogy, what corresponds to Static Typing (Java/C++)?
💡 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.
In the “Sticker vs. Box” analogy, what corresponds to Dynamic Typing (Python)?
💡 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.
Where is the “Type” tied to in Python?
💡 Explanation
The Object in Memory.
The variable is just a name tag. The actual object (e.g., the number 5) holds the type information.
What happens if you run x = 5 then x = "Guru"?
💡 Explanation
Allowed.
You are simply peeling the sticker off the Integer 5 and sticking it onto the String "Guru".
When does Python check for type errors?
💡 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.
When does Java/C++ check for type errors?
💡 Explanation
Compile Time.
The compiler screams at you before you can even run the program if you violate type rules.
Is Python “Strongly Typed” or “Weakly Typed”?
💡 Explanation
Strongly Typed.
Do not confuse Dynamic with Weak. Python is Strong because it forbids implicit weird conversions like 1 + "1".
What happens if you run 1 + "1" in Python?
💡 Explanation
TypeError.
JavaScript (Weak) would give “11”. Python (Strong) refuses to mix types implicitly.
What is the biggest risk of Dynamic Typing for Architects?
💡 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.
What feature (Python 3.5+) helps mitigate dynamic typing risks?
💡 Explanation
Type Hints.
Example: age: int = 25. This helps IDEs and linters catch errors before you run the code.
Do Type Hints prevent the code from running if violated?
💡 Explanation
No.
Type hints are for developers and tools (like MyPy). The Python interpreter completely ignores them at runtime.
What is the core philosophy of “Duck Typing”?
💡 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.
Does Python care if an object is officially a “File”?
💡 Explanation
No.
If you create a custom class that has a .read() method, Python will happily treat it like a file.
Why is Dynamic Typing generally slower than Static Typing?
💡 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.
What is a major benefit of Dynamic Typing?
💡 Explanation
Less Boilerplate.
You don’t need to write int, float, string everywhere. You just write logic, making it faster to write.
How does Python handle “Generic Functions” (one function for multiple types)?
💡 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.
What is the correct syntax for a Type Hint?
💡 Explanation
age: int = 25
This syntax (introduced in PEP 484) allows you to annotate the expected type.
When x = 5 is reassigned to x = "Guru", what happens to the 5?
💡 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.
Can you reuse a variable name for a different type in Static Typing (Java)?
💡 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.
What is the “Mystery Meat” variable problem?
💡 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.