Every value in Python has a type. Check it with type() or isinstance().
| Category | Types | Example |
|---|---|---|
| Text | str |
"hello" |
| Numbers | int, float, complex |
10, 3.14, 2+3j |
| Boolean | bool |
True, False |
| Sequences | list, tuple, range |
[1, 2], (1, 2) |
| Set | set, frozenset |
{1, 2} |
| Mapping | dict |
{"a": 1} |
| Nothing | NoneType |
None |
| Binary | bytes |
b"hi" |
Mutable vs immutable
- Immutable (cannot be changed in place):
int,float,str,tuple,bool - Mutable (can be changed):
list,dict,set
This matters when two variables refer to the same list — changing one changes both.
None
None means "no value". Check it with is None, not == None.
Truthy and falsy
These count as False in an if: 0, 0.0, "", [], {}, set(), None. Everything else is True.
Example
Example — Types and mutability
Python
items = [10, "pen", 2.5, True, None, (1, 2), {"a": 1}]
for item in items:
print(repr(item), "->", type(item).__name__)
# Mutable list shared by two names
a = [1, 2, 3]
b = a
b.append(4)
print("a:", a) # a changed too!
c = a.copy() # independent copy
c.append(5)
print("a:", a, "c:", c)
print(isinstance(3.5, float))
print(bool(""), bool("0"), bool([]))
Lists each type name (int, str, float, bool, NoneType, tuple, dict). a becomes [1, 2, 3, 4] because b is the same list; the copy c is separate. Last line: False True False.