Python16 min read

Python Data Types

Understand Python’s core data types, when to use them, and how type conversion works safely.

Emily Davis
September 13, 2025
3.9k190

A data type tells you what kind of value you are working with. Python automatically detects types, but you still need to understand them to avoid mistakes.

Core types you must know

name = "Sarah"                 # str
age = 30                       # int
height = 5.6                   # float
is_working = True              # bool
cities = ["Boston", "Dallas"]  # list
person = {"name": "Mike"}      # dict

Why types matter

If you mix types incorrectly, Python will complain.

Example:

age = "25"
# print(age + 5)  # error: can't add string and integer

Because "25" is text, not a number.

Check a type with type()

print(type("hello"))
print(type(10))
print(type(3.14))

Expected output:

<class 'str'>
<class 'int'>
<class 'float'>

Type conversion (a daily skill)

Convert string to integer:

age_text = "25"
age = int(age_text)
print(age + 5)

Expected output:

30

Convert integer to string (useful for messages):

count = 7
message = "Items: " + str(count)
print(message)

Expected output:

Items: 7

Important detail: int(float) does not round

price = 19.99
print(int(price))

Expected output:

19

If you want rounding, use round().

Graph: common conversions

flowchart LR
  A["'25' (str)"] -->|int()| B["25 (int)"]
  C["7 (int)"] -->|str()| D["'7' (str)"]
  E["19.99 (float)"] -->|int()| F["19 (int)"]

In the next lesson, you will dive into strings, because most beginner projects involve working with text.

#Python#Beginner#Data Types