Python Data Types Overview

In the last lesson, we learned f-strings. Now let’s step back and review the main Python data types together.

After learning Python f-Strings, we can format different values inside text. Now let’s step back and review Python’s main data types together. In this tutorial, we’ll learn about Python data types with easy examples.

πŸ”­ Let’s Take a Step Back

We have learned about a lot of things so far. Numbers. Strings. Booleans. Variables. Type conversion. Now it is time to put it all together. Let’s look at the big picture.

What types of data does Python have? How many are there? Which ones matter for beginners? Let’s go through them.

🧩 What Is a Data Type in Python?

A data type is just a category of data. It tells Python what kind of value we are working with. Is it a number? Is it text? Is it true or false? That is what a data type tells us.

Think of it like this. In a kitchen, we have different types of containers:

  • A bottle for water
  • A box for cereal
  • A bag for vegetables

Each container is made for a specific type of thing. We would not put water in a cereal box. Python is the same. Different data types for different kinds of data.

πŸ—‚οΈ The Main Data Types in Python

Python has several built-in data types. Here are the ones we will use most.

1️⃣ Integer (int)

Whole numbers. No decimal point.

age = 25
score = 100
temperature = -5

Type name: int

πŸ”£ Float (float)

Decimal numbers.

height = 5.9
price = 19.99
pi = 3.14159

Type name: float

πŸ“ String (str)

Text. Anything inside quotes.

name = "Alex"
message = "Hello, world"
address = "123 Main Street"

Type name: str

β˜‘οΈ Boolean (bool)

True or False. Nothing else.

is_student = True
is_raining = False

Type name: bool

πŸ“‹ List (list)

An ordered collection of items. We can change it.

numbers = [1, 2, 3, 4, 5]
names = ["Alex", "Sam", "John"]
mixed = [1, "hello", True, 3.14]

Type name: list

We will learn about lists in detail later.

πŸ“¦ Tuple (tuple)

An ordered collection. But we cannot change it.

coordinates = (10, 20)
colors = ("red", "green", "blue")

Type name: tuple

Notice the parentheses. That is how we tell a tuple from a list. We will learn about tuples later.

πŸ“– Dictionary (dict)

A collection of key-value pairs.

person = {"name": "Alex", "age": 25}
prices = {"apple": 1.50, "banana": 0.75}

Type name: dict

Notice the curly braces and the colons. That is how we tell a dictionary. We will learn about dictionaries later.

🧺 Set (set)

An unordered collection of unique items.

numbers = {1, 2, 3, 4, 5}
letters = {"a", "b", "c"}

Type name: set

Notice the curly braces. But no colons. That is how we tell a set from a dictionary. We will learn about sets later.

🚫 NoneType (None)

This is a special type. It means β€œnothing” or β€œno value.”

result = None

Type name: NoneType

It is not zero. It is not empty string. It is nothing.

πŸ” How to Check the Type in Python

We can always check the type of a value using type().

print(type(25)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type("hello")) # <class 'str'>
print(type(True)) # <class 'bool'>
print(type([1, 2, 3])) # <class 'list'>
print(type((1, 2, 3))) # <class 'tuple'>
print(type({"a": 1})) # <class 'dict'>
print(type({1, 2, 3})) # <class 'set'>
print(type(None)) # <class 'NoneType'>

That is how we check. Just use type().

πŸ”„ Mutable vs Immutable in Python

Here is an important idea. Some data types can be changed. Some cannot.

Mutable means β€œcan be changed.” Immutable means β€œcannot be changed.”

Let me show.

πŸ”’ Immutable Types

  • int β€” cannot change a number
  • float β€” cannot change a float
  • str β€” cannot change a string
  • bool β€” cannot change a boolean
  • tuple β€” cannot change a tuple

If we try to change an immutable type, we get an error.

name = "Alex"
name[0] = "B" # Error!

✏️ Mutable Types

  • list β€” can change a list
  • dict β€” can change a dictionary
  • set β€” can change a set
numbers = [1, 2, 3]
numbers[0] = 10 # Works!
print(numbers) # [10, 2, 3]

See? Lists can be changed. Strings cannot. This is important. Let’s remember it.

🏠 Python Data Types: A Real-Life Example

Think of it like this. A string is like a printed book. Once it is printed, we cannot change the words. We can only make a new book. A list is like a whiteboard. We can erase and write new things anytime.

That is the difference between immutable and mutable.

πŸ“Š Python Data Types Summary Table

Let me show a table.

TypeNameExampleMutable?
Integerint25No
Floatfloat3.14No
Stringstr"hello"No
BooleanboolTrueNo
Listlist[1, 2, 3]Yes
Tupletuple(1, 2, 3)No
Dictionarydict{"a": 1}Yes
Setset{1, 2, 3}Yes
NoneNoneTypeNoneNo

🎯 Which Python Data Types Should We Learn First?

For now, let’s focus on these four:

  1. int β€” whole numbers
  2. float β€” decimal numbers
  3. str β€” text
  4. bool β€” true or false

These are the building blocks. Everything else builds on top of them. The others β€” list, tuple, dict, set β€” we will learn later. They are collections. They hold multiple values.

πŸ” Converting Between Python Data Types

We learned this in the type conversion article. But let me remind us.

x = 25
print(str(x)) # "25"
print(float(x)) # 25.0
print(bool(x)) # True
y = "25"
print(int(y)) # 25
print(float(y)) # 25.0

We can convert between most types. But not all conversions make sense.

z = "hello"
print(int(z)) # Error! Cannot convert "hello" to a number

So let’s be careful.

πŸ’» A Complete Python Data Types Example

Let’s put it all together.

# Different types of data
name = "Alex" # str
age = 25 # int
height = 5.9 # float
is_student = True # bool
# Print them
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Height: {height}")
print(f"Is student: {is_student}")
# Print their types
print()
print(f"Type of name: {type(name)}")
print(f"Type of age: {type(age)}")
print(f"Type of height: {type(height)}")
print(f"Type of is_student: {type(is_student)}")

Output

Name: Alex
Age: 25
Height: 5.9
Is student: True
Type of name: <class 'str'>
Type of age: <class 'int'>
Type of height: <class 'float'>
Type of is_student: <class 'bool'>

See? Each value has a type. And Python knows what it is.

πŸ’‘ Why Does This Matter?

We might be thinking β€” why do we need to know all this? Because different types behave differently. We can do math with numbers. But not with strings. We can concatenate strings. But not with numbers. We can change a list. But not a string. So knowing the type helps us know what we can and cannot do.

Next, we will learn about Arithmetic Operators so we can start doing calculations with values.