Data Types Overview
Meet all the core building blocks Python uses to store information — numbers, text, booleans, collections, and more.
Every piece of information in a program has a type — a label that tells Python what kind of thing it is and what you can do with it. A phone number is different from a name, which is different from a yes/no answer. Python has built-in types for all of these situations. Think of types as different containers: you would not store soup in a paper bag or carry sand in a colander. The right container matters.
See it in action
— step through the idea, then dive into the details below.Python Labels Everything
Every value in Python has a type — a label that tells Python what kind of thing it is. The right type means Python knows what you can do with a value.
Types are like labeled boxes
Imagine a moving company with boxes labeled BOOKS, FRAGILE, CLOTHES. Python's data types are those labels. The label tells everyone handling the box what is inside and how to treat it. Python uses the label to decide what operations make sense — you can multiply a number, but you cannot multiply a sentence.
#Numbers: int and float
Python has two main number types. `int` (integer) holds whole numbers — no decimal point. `float` (floating-point) holds numbers with a decimal point. Use int for counting things; use float for measuring things.
age = 28 # int — a whole number
price = 9.99 # float — has a decimal point
print(age)
print(price)#Text: str (string)
A `str` (string) holds text — any sequence of characters wrapped in quotes. You can use single quotes 'hello' or double quotes "hello". Strings are used for names, messages, file paths, and anything else that is human-readable text.
greeting = "Hello, world!"
username = 'ada_lovelace'
print(greeting)
print(username)#True or False: bool
A `bool` (boolean) can only ever be one of two values: True or False. Booleans are the language of decisions. Whenever Python needs to make a choice — run this code or not? — it relies on a bool. Notice that True and False are capitalized; that is not optional.
is_logged_in = True
has_premium = False
print(is_logged_in)
print(has_premium)Capitalization matters for booleans
True and False must start with a capital letter. Writing true or false (lowercase) will cause a NameError because Python will think you mean a variable named true — which does not exist.
#Ordered Collections: list and tuple
Sometimes you need to store several values together in order. Python gives you two options: - `list` — an ordered, changeable collection. Written with square brackets [...]. - `tuple` — an ordered, unchangeable collection. Written with parentheses (...).
Think of a list as a shopping list you can edit, and a tuple as the days of the week — they are fixed forever.
fruits = ["apple", "banana", "cherry"] # list
days = ("Mon", "Tue", "Wed") # tuple
print(fruits)
print(days)#Key-Value Pairs: dict
A `dict` (dictionary) stores pairs of keys and values — like a real dictionary where you look up a word (key) to find its definition (value). Dicts use curly braces {...} with a colon separating each key from its value.
person = {
"name": "Ada",
"age": 36,
"is_admin": True
}
print(person["name"])
print(person["age"])#Unique Items: set
A `set` is an unordered collection that automatically removes duplicates. If you only care whether something is present or not — and not the order — a set is the right tool. Sets also use curly braces, but without key-value pairs.
tags = {"python", "beginner", "python", "code"}
print(tags)#Nothing at All: NoneType
Sometimes a variable intentionally holds no value. Python uses the special keyword None for this. Its type is called NoneType. You will often see None as a default before a value is assigned, or as a return value from a function that does not explicitly return anything.
result = None
print(result)
print(type(result))#Checking Types with type()
Not sure what type a value is? Ask Python directly using the built-in `type()` function. Pass any value inside the parentheses and Python will tell you its type. This is extremely handy when debugging.
print(type(42))
print(type(3.14))
print(type("hello"))
print(type(True))
print(type([1, 2, 3]))
print(type({"a": 1}))
print(type(None))Everything in Python is an object
You will notice that type() says <class 'int'>, not just int. That is because in Python, every value is an object — even a simple number like 42. An object is a value that bundles data with built-in capabilities. This is one of Python's most powerful ideas, and you will learn more about it in later lessons.
#Mutable vs Immutable — a quick peek
Some types can be changed after they are created — they are called mutable. Others are frozen once created — they are called immutable.
- Mutable:
list,dict,set— you can add, remove, or change their contents. - Immutable:
int,float,str,bool,tuple,NoneType— once created, the value itself cannot be altered.
This distinction matters a lot as you write bigger programs. We will explore it deeply in dedicated lessons.
Use type() whenever you feel lost
Beginners often get errors because they accidentally mix up types — for example, trying to add a number to a string. Any time you are confused about what a variable holds, just print type(your_variable) and Python will tell you instantly.
What does the type() function return when called on the value 3.14?
Key takeaways
- Python's core types are int, float, str, bool, list, tuple, dict, set, and NoneType — each designed for a specific kind of data.
- Use type() to inspect any value and find out its type — great for debugging.
- In Python, every value is an object, even simple numbers and booleans.
- Mutable types (list, dict, set) can be changed after creation; immutable types (int, float, str, tuple) cannot.
- None is Python's way of representing 'no value' — it is not zero or an empty string, it is the deliberate absence of a value.
What does this code print?
score = 42
price = 9.99
print(type(score))
print(type(price))This code has a bug. What is wrong?
is_active = true
print(is_active)Complete the code so it creates a dictionary and prints the value stored under the key "name".
person = {"name": "Ada", "age": 36} print(person[])
Put these lines in the right order to create a list of fruits and print its type.
print(fruits)
print(type(fruits))
fruits = ["apple", "banana", "cherry"]
Create one variable for each of the following types: int, float, str, bool, list, and dict. Then print the type of each variable using type(). Try to pick values that mean something to you — your age, a favourite food, etc.
Try it live — edit the code and hit Run to execute real Python: