🎩 Master Quiz: Data Types
20 Questions. Prove you know your Containers!
Green = Correct, Red = Incorrect.
In the “Containers” analogy, what is a Tuple?
💡 Explanation
A Sealed Amazon Parcel.
Once packed (created), you cannot add, remove, or change items inside a tuple. It is Immutable.
How does Python interpret x = 5.0?
💡 Explanation
Float.
Python sees the decimal point and automatically assigns the type as float.
Which function should you use to check types in production code?
💡 Explanation
isinstance().
isinstance() supports inheritance (subclasses), whereas type() does not, making isinstance cleaner and safer.
Which of the following data types is Mutable?
💡 Explanation
List.
Lists are like backpacks; you can add, remove, or change the contents after creating them.
Can you use a List as a Key in a Dictionary?
💡 Explanation
No.
Dictionary keys must be Immutable (Hashable). Since lists can change, they cannot be hashed and thus cannot be keys.
What happens if you run "5" + 5 in Python?
💡 Explanation
TypeError.
Python is Strongly Typed. It refuses to implicitly guess whether you want to do math or string concatenation. You must convert one type manually.
Why is b"password" different from "password"?
💡 Explanation
One is Bytes, one is String.
Crucial for encryption and networking! Strings are text; Bytes are raw binary data. They are not interchangeable without encoding/decoding.
Which data type is best for storing a collection of Unique IP addresses?
💡 Explanation
Set.
Sets automatically remove duplicates. If you add the same IP twice, the set keeps only one.
What is a Dictionary compared to?
💡 Explanation
A Phonebook.
You look up a “Key” (Name) to find the “Value” (Number).
Which type is best for Database Credentials (host, port) that shouldn’t change?
💡 Explanation
Tuple.
Since tuples are immutable, they prevent accidental modification of critical configuration data during runtime.
What is an Integer compared to?
💡 Explanation
A Solid Brick.
It is whole, unbreakable, and doesn’t have parts (e.g., 5, 100).
What is a String compared to?
💡 Explanation
A Necklace of Beads.
It is a sequence of individual characters strung together.
Why is Python generally slower than C?
💡 Explanation
Dynamic Typing Overhead.
Python has to check the type of every object at runtime before performing operations, adding overhead compared to statically typed languages.
What is the risk of passing Mutable types to functions?
💡 Explanation
Unintended side effects.
If a function modifies a list passed to it, the original list changes everywhere in your program.
What does “Dynamic Typing” mean?
💡 Explanation
Type is bound to the Object.
A variable is just a tag. You can move the tag from an Integer to a String without error.
When handling network packets, which type is used?
💡 Explanation
Bytes.
Network data is raw binary. You must decode it (bytes) into text (str) to read it.
Which syntax creates a Tuple?
💡 Explanation
Parentheses ().
Square brackets [] are for Lists, Curly braces {} are for Dicts/Sets.
Which syntax creates a Dictionary?
💡 Explanation
Curly braces with colons {"k": "v"}.
This defines the Key-Value pair mapping.
What is the type of None?
💡 Explanation
NoneType.
None is a special singleton object representing the absence of a value.
What is a List compared to?
💡 Explanation
A Backpack.
You can put things in, take things out, and rearrange them (Mutable).