Python has several built-in data types that are used to store different kinds of information. Understanding these is fundamental to programming in Python.
1. Numbers
Python supports integers, floating-point numbers, and complex numbers.
x = 5 # Integer
pi = 3.14 # Float
z = 2 + 3j # Complex number
2. Strings
Strings are sequences of characters, used to store text.
name = "Alice"
greeting = 'Hello, world!'
3. Booleans
Booleans represent True or False values.
is_active = True
is_admin = False
4. Lists
Lists are ordered, mutable collections of items.
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
5. Tuples
Tuples are ordered, immutable collections.
point = (10, 20)
6. Dictionaries
Dictionaries store key-value pairs.
person = {"name": "Alice", "age": 30}
7. Sets
Sets are unordered collections of unique items.
unique_numbers = {1, 2, 3, 2}
# unique_numbers will be {1, 2, 3}
Summary Table
| Type | Example | Description |
|---|---|---|
| int | x = 5 |
Integer number |
| float | pi = 3.14 |
Floating-point number |
| complex | z = 2 + 3j |
Complex number |
| str | name = "Alice" |
String (text) |
| bool | is_active = True |
Boolean value |
| list | [1, 2, 3] |
Ordered, mutable collection |
| tuple | (1, 2, 3) |
Ordered, immutable collection |
| dict | {"a": 1, "b": 2} |
Key-value pairs |
| set | {1, 2, 3} |
Unordered, unique items |
| ← Previous: Variables and Assignment | Next: Control Flow → |
|---|