Data Types
Learn about the core data types in Python — int, float, str, bool, and None.
Data Types
Every value in Python has a type. The type tells Python what kind of data it is and what you can do with it. You cannot add a number to a sentence, for example — Python needs to know the type to understand what operations make sense.
Python has five core built-in types you will use constantly:
| Type | Example | Meaning |
|---|---|---|
int | 42 | Whole numbers |
float | 3.14 | Decimal numbers |
str | "hello" | Text |
bool | True | True or False |
NoneType | None | No value at all |
int — whole numbers
An int is any whole number, positive or negative, with no decimal point.
age = 25
score = -10
year = 2024
print(type(age)) # <class 'int'>Integers in Python have no size limit. You can work with numbers as large as your memory allows — no overflow errors like in some other languages.
big = 999999999999999999999999
print(big + 1) # works perfectly finefloat — decimal numbers
A float is a number with a decimal point.
price = 9.99
temperature = -3.5
pi = 3.14159
print(type(price)) # <class 'float'>You can also write floats using scientific notation:
tiny = 1.5e-4 # means 1.5 × 10⁻⁴ = 0.00015
large = 2.5e6 # means 2.5 × 10⁶ = 2500000.0Floats are not perfectly precise. This is not a Python bug — it is how decimal numbers work in computer memory.
print(0.1 + 0.2) # 0.30000000000000004For financial calculations where precision matters, use Python's decimal module instead.
str — text
A str (string) is any sequence of characters wrapped in quotes. You can use single quotes or double quotes — both work the same way.
name = "Ali"
city = 'Lahore'
message = "It's a great day" # single quote inside double quotes — fine
print(type(name)) # <class 'str'>For text that spans multiple lines, use triple quotes:
paragraph = """
Python is a great language.
It is easy to read and write.
"""
print(paragraph)Strings are covered in much more depth in the Data Structures section. For now, just know they hold text.
bool — True or False
A bool has exactly two possible values: True or False. Notice the capital letters — Python is case-sensitive, so true and false will not work.
is_logged_in = True
has_error = False
print(type(is_logged_in)) # <class 'bool'>Booleans are the result of comparisons:
print(10 > 5) # True
print(10 == 5) # False
print(10 != 5) # TrueUnder the hood, True is just 1 and False is just 0 in Python. This means you can do arithmetic with them — though you rarely need to:
print(True + True) # 2
print(False + 1) # 1None — no value
None is Python's way of representing the absence of a value. It is not zero, not an empty string — it means nothing at all.
result = None
print(result) # None
print(type(result)) # <class 'NoneType'>You will see None in a few common situations:
# A function that returns nothing gives back None
def do_something():
pass
output = do_something()
print(output) # NoneTo check if something is None, use is — not ==:
result = None
if result is None:
print("No value yet")is checks if two things are the exact same object in memory. For None, this is the right check because there is only ever one None object in Python.
How Python decides the type
You never declare a type — Python looks at the value and decides:
x = 10 # int — no decimal point
x = 10.0 # float — has a decimal point
x = "10" # str — wrapped in quotes
x = True # bool — is True or False
x = None # NoneTypeThis means 10, 10.0, and "10" are three completely different things in Python.
print(10 == 10.0) # True — same numeric value
print(10 == "10") # False — number vs string, never equalSummary
| Type | Example values | Use for |
|---|---|---|
int | 0, 42, -7 | Counting, indexing, whole numbers |
float | 3.14, -0.5, 1e10 | Measurements, decimals, math |
str | "hello", 'x' | Text, names, messages |
bool | True, False | Conditions, flags, on/off states |
None | None | Missing values, empty results |