What You Will Learn
Every value in Python has a type. The type determines what you can do with the value. This lesson covers the four most important types.
int — Whole Numbers
int (integer) represents whole numbers — no decimal point:
age = 25
score = -10
year = 2026
print(type(age))
Expected output:
<class 'int'>
type() tells you what type a value is. You can do arithmetic with integers:
print(10 + 3) # 13
print(10 - 3) # 7
print(10 * 3) # 30
print(10 // 3) # 3 (integer division, rounds down)
print(10 % 3) # 1 (remainder)
float — Decimal Numbers
float represents numbers with a decimal point:
height = 1.75
temperature = -3.5
pi = 3.14159
print(type(height))
Expected output:
<class 'float'>
Most arithmetic works the same as with integers:
print(10 / 3) # 3.3333... (regular division always returns float)
print(1.5 + 2.5) # 4.0
print(2.0 ** 3) # 8.0 (exponentiation)
str — Text
str (string) represents text. Strings are always wrapped in quotes:
name = "Alice"
greeting = 'Hello, world!'
empty = ""
print(type(name))
Expected output:
<class 'str'>
You can join strings together with +:
first = "Hello"
second = "world"
print(first + ", " + second + "!")
Expected output:
Hello, world!
You cannot add a string and a number directly:
age = 25
print("I am " + age + " years old") # TypeError!
Convert the number to a string first:
age = 25
print("I am " + str(age) + " years old")
Expected output:
I am 25 years old
bool — True or False
bool (boolean) has only two possible values: True and False:
is_raining = True
is_sunny = False
print(type(is_raining))
Expected output:
<class 'bool'>
Booleans come from comparisons:
print(10 > 5) # True
print(10 < 5) # False
print(10 == 10) # True (== checks equality)
print(10 != 5) # True (!= checks inequality)
You will use booleans constantly when making decisions in your programs (covered in a later lesson).
Converting Between Types
Python can convert between types:
# int to float
x = float(42)
print(x) # 42.0
# float to int (truncates decimal)
y = int(3.9)
print(y) # 3
# number to string
z = str(100)
print(z) # "100"
print(type(z)) # <class 'str'>
# string to int (only works if the string looks like a number)
n = int("42")
print(n + 1) # 43
What You Learned
| Type | Example | Used For |
|---|---|---|
int | 42, -5 | Whole numbers |
float | 3.14, -0.5 | Decimal numbers |
str | "hello" | Text |
bool | True, False | Yes/no values |
In the next lesson, you will learn how to work with strings in more detail — slicing, searching, and formatting.