πŸ§™β€β™‚οΈ Python Wizard!

Data Types

πŸ“˜ Lesson: Understanding Python Data Types

Data types are the foundation of any programming language they tell Python what kind of data it’s working with and how to handle it. In Python, every piece of data is an object, and every object has a type.

Python is dynamically typed, meaning:

                
                    age = 5         # int
                    pi = 3.14       # float
                    name = "Alice"  # str
                
            

Core Data Types

int – Integer

Whole numbers like 10, -3, or 0.

                
                    score = 100
                    year = 2025
                
            
float – Floating Point Number

Numbers with decimal points.

                
                    price = 19.99
                    temperature = -3.5
                
            
str – String

Text data enclosed in quotes.

                
                    message = "Hello, Python!"
                    initial = 'A'
                
            
bool – Boolean

True or False values used in logic.

                
                    is_logged_in = True
                    is_complete = False
                
            

Collection Data Types

list – Ordered, Mutable Collection
                
                    colors = ["red", "green", "blue"]
                    colors.append("yellow")
                
            
tuple – Ordered, Immutable Collection
                
                    dimensions = (1920, 1080)
                
            
dict – Dictionary (Key-Value Pairs)
                
                    person = {"name": "Bob", "age": 30}
                    print(person["name"])
                
            
set – Unordered, Unique Items
                
                    unique_ids = {1, 2, 3, 2}
                    print(unique_ids)  # {1, 2, 3}
                
            

Type Checking and Conversion

                type(3.14)     # <class 'float'>
                    str(42)        # "42"
                    int("10")      # 10
                    bool("")       # False
                
            

πŸ€” Why Data Types Matter


πŸ§ͺ Quick Challenge!

                
                    a = "5"
                    b = 3
                    print(a * b)  # What does this output?
                
            

Answer: "555" β€” the string "5" is repeated 3 times!


🧠 Quick Quiz: Data Types

1. What data type would 3.14 be in Python?



2. What is the correct data type for "Hello World"?