Python Data Types
Python · Beginner
Definition
Python's core types are int, float, str, bool, list, tuple, set and dict.
Choosing the right type makes code faster and simpler.
Diagram
Flowchart
Example: Inspect types
for v in [5, 2.5, 'hi', [1], (1,), {1}, {'a': 1}]:
print(type(v).__name__)Output: int float str list tuple set dict
Complexity
dict/set lookup O(1) average · list search O(n)
Key points
- Only immutable types can be dict keys
- Sets remove duplicates
Interview questions
List vs tuple?
Lists are mutable; tuples are immutable and can be dict keys.