Python Data Types Quiz
Progress
Score: 0/20
๐ฉ Master Quiz: Data Types
20 Questions. Prove you know your Containers! Green = Correct, Red = Incorrect.
BeginnerAnalogy
In the "Containers" analogy, what is a Tuple?โ
- **A) A Backpack
** - **B) A Sealed Amazon Parcel
** - **C) A Necklace of Beads
** - **D) Water
**
๐ก Explanationโ
A Sealed Amazon Parcel.
Once packed (created), you cannot add, remove, or change items inside a tuple. It is Immutable.
BeginnerType ID
How does Python interpret x = 5.0?โ
- **A) Integer (int)
** - **B) String (str)
** - **C) Float (float)
** - **D) Decimal
**
๐ก Explanationโ
Float.
Python sees the decimal point and automatically assigns the type as float.
ArchitectBest Practice
Which function should you use to check types in production code?โ
- **A)
type(x) == int``** - **B)
isinstance(x, int)``** - **C)
check_type(x)``** - **D)
x.is_type(int)``**
๐ก Explanationโ
isinstance().
isinstance() supports inheritance (subclasses), whereas type() does not, making isinstance cleaner and safer.
IntermediateMutability
Which of the following data types is Mutable?โ
- **A) Tuple
** - **B) String
** - **C) List
** - **D) Integer
**
๐ก Explanationโ
List.
Lists are like backpacks; you can add, remove, or change the contents after creating them.
AdvancedDictionary Keys
Can you use a List as a Key in a Dictionary?โ
- **A) Yes, always
** - **B) No, because lists are Mutable
** - **C) Yes, if the list is empty
** - **D) Only in Python 3.10+
**
๐ก Explanationโ
No.
Dictionary keys must be Immutable (Hashable). Since lists can change, they cannot be hashed and thus cannot be keys.
BeginnerStrong Typing
What happens if you run "5" + 5 in Python?โ
- **A) "55"
** - **B) 10
** - **C) TypeError (Crash)
** - **D) None
**
๐ก 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.
ArchitectDevSecOps
Why is b"password" different from "password"?โ
- **A) One is Bytes, one is String
** - **B) One is encrypted, one is not
** - **C) One is mutable, one is not
** - **D) There is no difference
**
๐ก 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.
IntermediateUse Case
Which data type is best for storing a collection of Unique IP addresses?โ
- **A) List
** - **B) Set
** - **C) Tuple
** - **D) Dictionary
**
๐ก Explanationโ
Set.
Sets automatically remove duplicates. If you add the same IP twice, the set keeps only one.
IntermediateAnalogy
What is a Dictionary compared to?โ
- **A) A Phonebook
** - **B) A Backpack
** - **C) A Brick
** - **D) A Necklace
**
๐ก Explanationโ
A Phonebook.
You look up a "Key" (Name) to find the "Value" (Number).
ArchitectArchitecture
Which type is best for Database Credentials (host, port) that shouldn't change?โ
- **A) List
** - **B) Set
** - **C) Tuple
** - **D) String
**
๐ก Explanationโ
Tuple.
Since tuples are immutable, they prevent accidental modification of critical configuration data during runtime.
BeginnerAnalogy
What is an Integer compared to?โ
- **A) A Solid Brick
** - **B) Water
** - **C) A Backpack
** - **D) A Parcel
**
๐ก Explanationโ
A Solid Brick.
It is whole, unbreakable, and doesn't have parts (e.g., 5, 100).
BeginnerAnalogy
What is a String compared to?โ
- **A) Water
** - **B) A Necklace of Beads
** - **C) A Phonebook
** - **D) A Brick
**
๐ก Explanationโ
A Necklace of Beads.
It is a sequence of individual characters strung together.
ArchitectLimitations
Why is Python generally slower than C?โ
- **A) Dynamic Typing Overhead
** - **B) It compiles to binary
** - **C) It uses too much hard drive space
** - **D) It cannot handle integers
**
๐ก 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.
AdvancedRisk
What is the risk of passing Mutable types to functions?โ
- **A) It crashes the compiler
** - **B) Unintended side effects (Data Modification)
** - **C) It converts them to Immutable
** - **D) It creates a deadlock
**
๐ก Explanationโ
Unintended side effects.
If a function modifies a list passed to it, the original list changes everywhere in your program.
IntermediateDynamic Typing
What does "Dynamic Typing" mean?โ
- **A) Type is bound to the Object, not the Variable
** - **B) Variables cannot change type
** - **C) You must declare types like 'int x'
** - **D) Python converts everything to strings
**
๐ก 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.
ArchitectNetworking
When handling network packets, which type is used?โ
- **A) String
** - **B) List
** - **C) Bytes
** - **D) Float
**
๐ก Explanationโ
Bytes.
Network data is raw binary. You must decode it (bytes) into text (str) to read it.
BeginnerSyntax
Which syntax creates a Tuple?โ
- **A)
[1, 2]``** - **B)
(1, 2)``** - **C)
{1, 2}``** - **D)
<1, 2>``**
๐ก Explanationโ
Parentheses ().
Square brackets [] are for Lists, Curly braces {} are for Dicts/Sets.
BeginnerSyntax
Which syntax creates a Dictionary?โ
- **A)
("key", "value")``** - **B)
["key", "value"]``** - **C)
{"key": "value"}``** - **D)
key = value``**
๐ก Explanationโ
Curly braces with colons {"k": "v"}.
This defines the Key-Value pair mapping.
IntermediateNull Value
What is the type of None?โ
- **A) NoneType
** - **B) int
** - **C) bool
** - **D) empty
**
๐ก Explanationโ
NoneType.
None is a special singleton object representing the absence of a value.
BeginnerAnalogy
What is a List compared to?โ
- **A) A Sealed Parcel
** - **B) A Backpack
** - **C) Water
** - **D) A Brick
**
๐ก Explanationโ
A Backpack.
You can put things in, take things out, and rearrange them (Mutable).
๐ Quiz Complete!โ
Your Final Score:
0/20 Novice
Keep practicing to reach Architect level!
- **โบ Retake Quiz
**