
đ Lesson 6: Python Data Types (ááąááŹáĄááťááŻá¸áĄá áŹá¸ááťáŹá¸)
1. Data Type áááŻááŹááŹáá˛?
ááźááşáᏠâ Data Type áááŻáᏠVariable áá˛áážáŹ ááááşá¸ááŹá¸áá˛áˇ áááşáááŻá¸ (value) áá˛áˇ áĄááťááŻá¸áĄá áŹá¸ááᯠáááŻáááŻáááşá
English â A data type defines the kind of value a variable holds.
2. Python áá˛áˇ áĄááá Data Types
| Data Type | áĄáááş (ááźááşááŹ) | áĽááᏠ|
|---|---|---|
| int (Integer) | ááááşá¸ááźááˇáş | age = 25 |
| float (Floating point) | ááżáááááşá¸ | pi = 3.14 |
| str (String) | á áŹááŹá¸ | name = "Sai" |
| bool (Boolean) | áĄáážááş/áĄáážáŹá¸ | is_active = True |
3. Collection Types (áĄá áŻáĄááąá¸ Data Types)
| Data Type | áĄáááş (ááźááşááŹ) | Properties |
|---|---|---|
| list | á áŹáááşá¸ | ordered, changeable |
| tuple | áááźáąáŹááşá¸áá˛áááŻááşáá˛áˇ á áŹáááşá¸ | ordered, unchangeable |
| set | áááşááážááá˛áˇ áĄá ᯠ| unordered, no duplicates |
| dict (Dictionary) | Key-Value á áŻáś | key-value pairs, changeable |
4. Data Type ááᯠá á áşáááŻáˇ
type()â Variable áá˛áˇ data type ááᯠááźáááşisinstance()â Variable áá áşááŻá data type áá áşááŻáá˛áˇ áááŻááşááááŻááş á á áşáááŻááşáááş
5. áĄááťááşá¸ááťáŻááş
â Data Type = Variable áá˛á áááşáááŻá¸áá˛áˇ áĄááťááŻá¸áĄá áŹá¸
â
áĄááźáąááś â int, float, str, bool
â
Collection â list, tuple, set, dict
â
á
á
áşáááŻáˇ â type(), isinstance()
python
# ===== 1. Basic Data Types Examples =====
# Integer
age = 25
print(f"Age: {age}, Type: {type(age)}")
# Float
pi = 3.14
print(f"Pi: {pi}, Type: {type(pi)}")
# String
name = "Sai"
print(f"Name: {name}, Type: {type(name)}")
# Boolean
is_active = True
print(f"Active: {is_active}, Type: {type(is_active)}")
print("\n===== 2. Collection Types =====")
# List
fruits = ["apple", "banana", "cherry"]
print(f"List: {fruits}, Type: {type(fruits)}")
# Tuple
colors = ("red", "green", "blue")
print(f"Tuple: {colors}, Type: {type(colors)}")
# Set
nums = {1, 2, 3, 3}
print(f"Set: {nums}, Type: {type(nums)}")
# Dictionary
person = {"name": "Sai", "age": 25}
print(f"Dict: {person}, Type: {type(person)}")
print("\n===== 3. Type Checking with isinstance() =====")
x = 10
print(f"x = {x}")
print(f"isinstance(x, int): {isinstance(x, int)}")
print(f"isinstance(x, float): {isinstance(x, float)}")You should see
Age: 25, Type: Pi: 3.14, Type: Name: Sai, Type: Active: True, Type: ===== 2. Collection Types ===== List: ['apple', 'banana', 'cherry'], Type: Tuple: ('red', 'green', 'blue'), Type: Set: {1, 2, 3}, Type: Dict: {'name': 'Sai', 'age': 25}, Type: ===== 3. Type Checking with isinstance() ===== x = 10 isinstance(x, int): True isinstance(x, float): False