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'}
Top comments (0)