What are the basic built-in data types in Python?
Python has several built-in data types organized into categories:
Numeric types:
int-- arbitrary-precision integers (e.g.,42,-7,10**100)float-- IEEE 754 double-precision floating point (e.g.,3.14,-0.001,1e10)complex-- complex numbers with real and imaginary parts (e.g.,3+4j)
Sequence types:
str-- immutable sequence of Unicode characterslist-- mutable ordered sequencetuple-- immutable ordered sequence
Set types:
set-- mutable unordered collection of unique elementsfrozenset-- immutable version of set
Mapping type:
dict-- mutable key-value mapping
Boolean type:
bool--TrueorFalse(subclass ofint)
None type:
NoneType-- singletonNone, represents absence of a value
Binary types:
bytes,bytearray,memoryview
Everything in Python is an object, including these types themselves. You can check a value's type with type() and verify membership with isinstance().
1. Numeric: int, float, complex
2. Text: str
3. Sequence: list, tuple, range
4. Set: set, frozenset
5. Mapping: dict
6. Boolean: bool
7. None: NoneType
8. Binary: bytes, bytearray, memoryview
# Numeric types
print(type(42)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type(3+4j)) # <class 'complex'>
# Text type
print(type("hello")) # <class 'str'>
# Sequence types
print(type([1, 2, 3])) # <class 'list'>
print(type((1, 2, 3))) # <class 'tuple'>
# Set types
print(type({1, 2, 3})) # <class 'set'>
# Mapping type
print(type({"a": 1})) # <class 'dict'>
# Boolean and None
print(type(True)) # <class 'bool'>
print(type(None)) # <class 'NoneType'>
# bool is a subclass of int
print(isinstance(True, int)) # True
print(True + True) # 2
- •Everything in Python is an object, including types themselves
- •bool is a subclass of int (True == 1, False == 0)
- •Python integers have arbitrary precision -- no overflow
- •NoneType has exactly one instance: None
- •Strings are sequences of Unicode codepoints, not bytes
- •An empty dict is {} but an empty set must be set(), not {} -- {} creates a dict
- •bool is a subclass of int, so isinstance(True, int) returns True
- •float has limited precision -- 0.1 + 0.2 != 0.3 exactly
- •None is a singleton: always use 'is None' rather than '== None'