A data type tells Python:
“What kind of value is this?”
For example:
10 → integer"Hello" → string3.14 → floatPython needs this so it knows:
Think of It Like This
If your program is a kitchen:
🔢 Main Python Data Types
| Data Type | Description | Example | |-----------|---------------------------------|---------------| | int | Whole numbers | 10, -5, 200 | | float | Decimal numbers | 3.14, 2.5 | | complex | Complex numbers | 2+3j | | str | Text | "Hello" | | bool | True or False | True, False |
1️⃣ Integer (int)
age = 25
Whole numbers:
2️⃣ Float (float)
price = 99.99
Numbers with decimal points.
3️⃣ String (str)
Text inside quotes:
name = "Danny"
You can use:
"Hello" 'Hello'
4️⃣ Boolean (bool)
Used for True / False:
is_logged_in = True
Very useful in:
5️⃣ Complex (complex)
Not common for beginners:
x = 2 + 3j
Used in scientific calculations.
What Are Data Structures?
A data structure is a way to:
store multiple values in one variable.
Instead of:
student1 = "John" student2 = "Mary" student3 = "David"
You can store them in one place.
Main Python Data Structures
| Data Structure | Description | Example |
|----------------|-------------------------------------|---------------------------|
| list | Ordered, changeable collection | [1, 2, 3] |
| tuple | Ordered, unchangeable collection | (1, 2, 3) |
| set | Unordered, no duplicates | {1, 2, 3} |
| dict | Key-value pairs | {"name": "John"} |
1. List ✅ (Most Common)
A list stores multiple items in order.
fruits = ["apple", "banana", "orange"]
Features:
✔ Ordered
✔ Changeable
✔ Allows duplicates
Accessing List Items
print(fruits[0])
Output:
apple
Changing List Items
fruits[1] = "grape"
2. Tuple
A tuple is like a list but:
❌ Cannot be changed after creation
numbers = (1, 2, 3)
Used when data should not change.
3. Set
A set:
unique_numbers = {1, 2, 3}
If you write:
{1, 1, 2, 2}
You get:
{1, 2}
4. Dictionary
Stores data in key → value format.
student = {
"name": "Danny",
"age": 25,
"course": "Python"
}
Accessing Dictionary Data
print(student["name"])
Output:
Danny
Data Type vs Data Structure
| Feature | Data Type | Data Structure | |---------------|---------------------------|------------------------------------| | Meaning | Type of a single value | Stores multiple values | | Example | int, float, string | list, tuple, set, dictionary | | Usage | Defines value behavior | Organizes collections of data |
Checking Data Types
Use:
type()
Example:
x = 10 print(type(x))
Output:
<class 'int'>
Type Conversion (Casting)
You can change data types:
age = "25" age = int(age)
Type Casting Table
| Function | Converts To | |----------|-------------| | int() | Integer | | float() | Float | | str() | String | | bool() | Boolean |
Real-Life Example
name = "Danny" # string
age = 25 # int
height = 1.75 # float
is_student = True # bool
courses = ["Python", "UI/UX"] # list
student = {
"name": name,
"age": age
}
When to Use Each Data Structure
| Use Case | Best Choice | |----------------------------------|------------| | Store many items (changeable) | List | | Store fixed data (unchangeable) | Tuple | | Remove duplicates | Set | | Store labeled data | Dictionary |
Summary
✅ Data Types = single values
✅ Data Structures = multiple values
They help you: