What are Python Data Types?
Learn Python's built-in data types - numeric, sequence, mapping, set, boolean, and None - with mutability rules, code examples, and common interview pitfalls.
Expected Interview Answer
Python's built-in data types fall into a handful of core families: numeric (int, float, complex), sequences (str, list, tuple, range), mappings (dict), sets (set, frozenset), booleans (bool), and None, and every value is an object whose type is determined dynamically at runtime rather than declared upfront.
Numeric types cover integers, floating-point decimals, and complex numbers, and Python promotes between them automatically during arithmetic. Sequence types like list, tuple, and str hold ordered items, differing mainly in mutability and content: lists are mutable and mixed-type, tuples are immutable, and strings hold only characters. dict maps hashable keys to values in insertion order, while set and frozenset store unique, unordered elements for fast membership tests. bool is technically a subclass of int (True equals 1, False equals 0), and None is the singleton representing no value. Only immutable types such as int, str, and tuple can be used as dict keys or set members because hashing requires the value never to change.
- Covers every common shape of data with a small, consistent set of built-ins
- Mutability rules make hashing and dict keys predictable
- Dynamic typing removes boilerplate type declarations
- Rich built-in methods on each type reduce need for custom code
- Clear separation of ordered, mapped, and unique-element collections
AI Mentor Explanation
Python data types are like roles on a scorecard: numbers are runs and overs, a tuple is the batting order announced before the toss, fixed for the innings, and a list is the field placements a captain freely rearranges. A dict maps each name to their stats, and a set is the list of players who took a wicket, no name repeated.
Step-by-Step Explanation
Step 1
Numeric types
int, float, and complex store whole numbers, decimals, and complex numbers, with automatic promotion in mixed arithmetic.
Step 2
Sequence types
str, list, tuple, and range hold ordered items; lists are mutable, tuples and strings are immutable.
Step 3
Mapping type
dict stores key-value pairs, preserving insertion order since Python 3.7, with O(1) average lookup by key.
Step 4
Set types
set and frozenset hold unique, unordered elements and support fast membership tests and set algebra.
Step 5
Boolean and None
bool is a subclass of int with only True/False values; None is the singleton for absence of a value.
Step 6
Mutability rule
Only immutable, hashable types can be dict keys or set members, because hashing depends on the value never changing.
What Interviewer Expects
- Names the core built-in type families, not just int/str/list
- Explains mutable vs immutable and why it matters for hashing
- Knows dict and set are hash-based with average O(1) lookup
- Understands bool is a subclass of int
- Can give a concrete example distinguishing list and tuple usage
Common Mistakes
- Saying tuples are just 'lists with parentheses' with no functional difference
- Forgetting dict keys must be hashable/immutable
- Claiming Python has no type system because it is dynamically typed
- Confusing set with list and assuming sets preserve order
- Not knowing bool is technically an int subtype
Best Answer (HR Friendly)
“Python organizes information into a small set of built-in data types: numbers, text, ordered lists, fixed tuples, key-value dictionaries, and unique-item sets. Each type is suited to a different kind of problem, and Python figures out which type to use automatically based on the value you give it.”
Code Example
age = 30 # int
price = 19.99 # float
name = "SkillVeris" # str
scores = [90, 85, 77] # list (mutable)
point = (10, 20) # tuple (immutable)
user = {"id": 1, "name": "Ada"} # dict
tags = {"python", "ai", "python"} # set (dedupes)
print(type(age), type(scores), type(user))
print(tags) # {'python', 'ai'} - duplicate 'python' collapsedFollow-up Questions
- What is the difference between a list and a tuple?
- Why must dictionary keys be hashable?
- How does Python decide a value's type at runtime?
- What is the difference between mutable and immutable objects?
- How do sets achieve fast membership testing?
MCQ Practice
1. Which of these is an immutable Python data type?
Tuples are immutable; once created, their contents cannot be changed, unlike list, dict, and set.
2. Which type can be used as a dictionary key?
Only hashable, immutable types like str, int, and tuple can be dictionary keys; list, dict, and set are unhashable.
3. What is bool in Python's type hierarchy?
bool is a subclass of int, so True behaves as 1 and False behaves as 0 in arithmetic.
Flash Cards
Name Python's core built-in type families. — Numeric, sequence, mapping, set, boolean, and None.
Which built-in types are immutable? — int, float, complex, str, tuple, frozenset, and bool.
What determines if a type can be a dict key? — It must be hashable, which requires immutability.
What is bool's relationship to int? — bool is a subclass of int; True == 1 and False == 0.