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

CategoryTypeExample
Textstr"hello"
Numbersint, float, complex42, 3.14, 2+3j
BooleanboolTrue, False
NothingNoneTypeNone
Sequenceslist, tuple, range[1, 2], (1, 2), range(5)
Mappingdict{"a": 1}
Setsset, frozenset{1, 2, 3}
Binarybytes, bytearrayb"data"

Checking a type

PY type.py
print(type("hello"))
print(type(42))
print(type(3.14))
print(type(True))
print(type(None))
print(type([1, 2]))
print(type({"a": 1}))
Output
<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:

PY isinstance.py
value = 3.5
print(isinstance(value, float))
print(isinstance(value, (int, float)))
print(isinstance(True, int))
Output
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.
PY mutability.py
word = "cat"
upper = word.upper()
print(word, upper)

pets = ["cat"]
pets.append("dog")
print(pets)
Output
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:

PY strong.py
age = 30
print("Age: " + age)
Output
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    print("Age: " + age)
          ~~~~~~~~^~~~~
TypeError: can only concatenate str (not "int") to str

JavaScript 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":

PY none.py
def find_user(user_id):
    if user_id == 1:
        return "Ana"
    return None

result = find_user(2)
print(result)
print(result is None)
Output
None
True

Always compare with is None / is not None rather than ==. Lesson 11 covers None and booleans together.

Try it yourself

Try it yourself
Console output