Data Types
Every value in Python has a type that decides what you can do with it. Python's built-in types cover text, numbers, true/false values, "nothing", and several kinds of collections. This lesson is a map of them; later lessons explore each in depth.
The built-in types
| Category | Type | Example |
|---|---|---|
| Text | str | "hello" |
| Numbers | int, float, complex | 42, 3.14, 2+3j |
| Boolean | bool | True, False |
| Nothing | NoneType | None |
| Sequences | list, tuple, range | [1, 2], (1, 2), range(5) |
| Mapping | dict | {"a": 1} |
| Sets | set, frozenset | {1, 2, 3} |
| Binary | bytes, bytearray | b"data" |
Checking a type
print(type("hello")) print(type(42)) print(type(3.14)) print(type(True)) print(type(None)) print(type([1, 2])) print(type({"a": 1}))
<class 'str'> <class 'int'> <class 'float'> <class 'bool'> <class 'NoneType'> <class 'list'> <class 'dict'>
To test a type in code, use isinstance, which also accepts a tuple of types:
value = 3.5 print(isinstance(value, float)) print(isinstance(value, (int, float))) print(isinstance(True, int))
True True True
The last line surprises people: bool is a subclass of int, so True behaves like 1 and False like 0 in arithmetic.
Mutable vs immutable
This distinction shapes how Python code behaves:
- Immutable types can't be changed after creation:
int,float,bool,str,tuple,frozenset,None. "Changing" one actually creates a new object. - Mutable types can be modified in place:
list,dict,set,bytearray.
word = "cat" upper = word.upper() print(word, upper) pets = ["cat"] pets.append("dog") print(pets)
cat CAT ['cat', 'dog']
String methods like upper() return a new string and leave the original alone. List methods like append() change the list itself. Only immutable values can be dictionary keys or set members (lessons 23–24).
Dynamic and strong typing
Python is dynamically typed — names don't have fixed types — but it's also strongly typed: it won't silently convert between unrelated types:
age = 30 print("Age: " + age)
Traceback (most recent call last):
File "main.py", line 2, in <module>
print("Age: " + age)
~~~~~~~~^~~~~
TypeError: can only concatenate str (not "int") to strJavaScript would quietly produce "Age: 30"; Python asks you to be explicit: "Age: " + str(age), or better, an f-string f"Age: {age}". Lesson 07 covers conversions.
None
None is Python's single "no value" object — used for missing results, optional arguments and "not set yet":
def find_user(user_id): if user_id == 1: return "Ana" return None result = find_user(2) print(result) print(result is None)
None True
Always compare with is None / is not None rather than ==. Lesson 11 covers None and booleans together.