
Python has several built-in data types, categorized into different groups based on their usage. Here’s a breakdown:
1. Numeric Types
- int → Integer values (e.g.,
10
,-5
,1000
) - float → Floating-point numbers (e.g.,
10.5
,-3.14
) - complex → Complex numbers (e.g.,
3 + 4j
,-2 - 7j
)
2. Sequence Types
- str → String (e.g.,
"Hello"
,'Python'
) - list → Ordered, mutable collection (e.g.,
[1, 2, 3]
) - tuple → Ordered, immutable collection (e.g.,
(1, 2, 3)
) - range → Sequence of numbers (e.g.,
range(5) → [0,1,2,3,4]
)
3. Set Types
- set → Unordered, unique collection (e.g.,
{1, 2, 3}
) - frozenset → Immutable set (e.g.,
frozenset({1, 2, 3})
)
4. Mapping Type
- dict → Key-value pairs (e.g.,
{"name": "Alice", "age": 25}
)
5. Boolean Type
- bool → Boolean values (
True
,False
)
6. Binary Types (Used for handling binary data)
- bytes → Immutable sequence of bytes
- bytearray → Mutable sequence of bytes
- memoryview → Memory view object
7. None Type
- NoneType → Represents the absence of a value (
None
)