Python · The language, not just syntax
What are Python's core data types and how do they behave?
Short answer
Python's core types include int, float, complex, bool, str, bytes, None, list, tuple, dict and set. The key distinction is mutable versus immutable, because it affects aliasing, hashing and safety.
A variable is a name bound to an object, not a typed storage location. Reassigning the name rebinds it to another object, which is why one name can refer to an int and later to a string. Every object carries its type, identity and value.
values = [42, 3.14, True, None, "text", b"bytes", (1, 2), [1, 2], {"a": 1}, {1, 2}]
for value in values:
print(type(value).__name__, value)
print(isinstance(True, int)) # True
print(type(True) is int) # FalseGrouping the built-ins
- Numeric: int, float, complex, bool, Decimal, Fraction
- Text and binary: str, bytes, bytearray, memoryview
- Sequences: list, tuple, range, str
- Mappings and sets: dict, set, frozenset
- Callables and modules: functions, methods, classes, modules
Immutable objects such as int, str and tuple cannot change after creation, so they are safe to share and can be hashable. Mutable objects such as list, dict and set can change in place, which means two names can observe the same mutation.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between a name and a value?
- 2Why is bool a subclass of int, and what problems does that cause?
- 3Which built-in types are hashable?
- 4When would you use Decimal instead of float?
Say it in the interview
Python has a compact set of built-in types, and I think about them mainly as mutable or immutable. Immutable values like int, str and tuple can be shared safely and may be hashable. Mutable values like list, dict and set can be changed in place, so aliasing matters. I also remember that bool subclasses int, and that Decimal exists when binary floating point rounding is unacceptable.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Python mock interview and get scored feedback on depth, clarity and confidence.