Python BasicsBeginner8 min08 / 63

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

Visual walkthrough1 / 6
1

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.

Think of types as labeled boxes: a BOOKS box and a FRAGILE box get handled very differently.
Think of it like

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.

Whole numbers are ints; decimals are floats.
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.

Both quote styles create a string.
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.

Booleans are always True or False — capital first letter.
is_logged_in = True
has_premium = False

print(is_logged_in)
print(has_premium)
Common mistake

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.

Square brackets for lists, parentheses for tuples.
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.

Look up a value by its key using square brackets.
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.

Duplicate 'python' was removed automatically. Order may vary.
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.

None means 'no value here yet'.
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.

type() reveals the type of any value.
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))
Note

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.

Tip

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.

Quick check

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.
Practice challenges
Test yourself · earn XP
0/4
Predict the output#1

What does this code print?

predict-output
score = 42
price = 9.99
print(type(score))
print(type(price))
Fix the bug#2

This code has a bug. What is wrong?

fix-bug
is_active = true
print(is_active)
Fill in the blank#3

Complete the code so it creates a dictionary and prints the value stored under the key "name".

person = {"name": "Ada", "age": 36}
print(person[])
Reorder the lines#4

Put these lines in the right order to create a list of fruits and print its type.

1
print(fruits)
2
print(type(fruits))
3
fruits = ["apple", "banana", "cherry"]
Your turn
Practice exercise

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:

solution.py · editable