Python - Data Types

python logo pixel art

Data types are the kinds of data that you can store.


Built-in Data Types


List vs Tuple

The main difference is that lists can be changed (mutable), while tuples cannot (immutable).

my_list = [1, 2, 3]
my_tuple = (1, 2, 3)

my_list[1] = 4 # <- Ok!
my_tuple[1] = 4 # <- Error!

Set vs FrozenSet

The main difference is that a set is mutable (can be changed), while a frozenset is immutable (cannot be changed).

x = { "a", "b", "c" }
y = frozenset(x)

x.add("d") # <- Ok!
y.add("d") # <- Error!

What is the 'range' data type?

The range data type is simply used in for-loops.

for n in range(10):
  print(n)

What is 'Iterables'?

any sequence that can be iterated over, such as: