Quest 1 β’ Lesson 2
π¦ Variables & Data Types
In Python, a variable is like a labeled box where you can store data. You can create a variable by giving it a name and assigning a value using the = sign.
"Variables store values that can be used and changed throughout your program."
variables.py
name = "Khurram"
age = 25
height = 5.9
is_student = True
print(name)
print(age)
print(height)
print(is_student)
age = 25
height = 5.9
is_student = True
print(name)
print(age)
print(height)
print(is_student)
π§ Python Data Types
"Khurram"β String (str): text inside quotes.25β Integer (int): whole numbers.5.9β Float: numbers with a decimal point.True/Falseβ Boolean (bool): True or False values.
Python automatically detects the data type based on the value you assign.
β¨ Challenge: Personal Details
Create variables to store your city (string), zip code (integer), and temperature (float). Then print them.
city = "Rawalpindi"
zip_code = 54000
temp = 30.5
print(city)
print(zip_code)
print(temp)
π Bonus: Check a Variable's Type
Use the builtβin type() function.
age = 25
print(type(age)) # Output: <class 'int'>
print(type(age)) # Output: <class 'int'>
β€οΈ Support Free Education
This course is 100% free. If it helps you, consider buying me a coffee.
β Buy Me a Coffeeβ‘οΈ Ready for more?
Next lesson: Working with Numbers & Strings β operations and formatting.
Continue to Lesson 1.3 β(Coming soon β check back or buy Pro Pack for instant access)