Python is a popular programming language known for its simplicity and readability. But before you dive deep into coding, one of the most important concepts to grasp is data types.
Think of data types like different kinds of boxes you can use to store information. Each box (data type) holds a specific kind of value — like numbers, words, lists of things, etc.
Below are some of the data types that are common;
**
1️⃣ Numbers
**
These are used to store numeric values.
Integers (int): Whole numbers — e.g., 3, 0, -5
Floats (float): Decimal numbers — e.g., 3.14, -0.5
Complex (complex): Numbers with real and imaginary parts — e.g., 2 + 3j
age = 21 # int
height = 5.6 # float
z = 2 + 3j # complex
2️⃣ Strings (str)
A string is a sequence of characters — usually used to represent text.
name = "Lilian"
greeting = 'Hello, world!'
**
3️⃣ Booleans (bool)
**
Booleans represent True or False values — great for decisions and logic.
is_logged_in = True
has_passed = False
**
4️⃣ Lists (list)
**
Lists are ordered collections of items — like a shopping list 🛒.
fruits = ["apple", "banana", "mango"]
numbers = [1, 2, 3, 4]
**
5️⃣ Tuples (tuple)
**
A tuple is just like a list — but it cannot be changed after creation.
It's immutable.
coordinates = (10, 20)
**
6️⃣ Dictionaries (dict)
**
Dictionaries store key-value pairs — like an ID and its name.
user = {
"name": "Lilian",
"age": 22,
"is_active": True
}
**
7️⃣ Sets (set)
**
A set is a collection of unique items, no duplicates allowed.
colors = {"red", "blue", "green", "red"}
print(colors) # {'red', 'blue', 'green'}