Variables, Data Types, Numbers & Casting
Variables store values. You assign with = — no type keyword needed.
Python Variables
Variables store values. You assign with = — no type keyword needed.
Use snake_case names like user_name. Start with a letter, not a number.
Real-life example: A variable is a labeled box in storage — the label stays, but you can swap what is inside.
course = "Python Zero to Pro"
lesson = 3
print(course, lesson)Python Data Types
Common types: str (text), int (whole numbers), float (decimals), bool (True/False), list, tuple, set, dict.
Use type() to inspect a value's type at runtime.
Real-life example: Data types are like container shapes — you would not pour soup into a letter envelope (str vs list).
name = "Meera" # str
age = 21 # int
gpa = 3.8 # float
active = True # bool
print(type(name), type(age))Python Numbers
int handles whole numbers; float handles decimals. Python supports +, -, *, /, //, %, and **.
Division / always returns float. // is floor division.
Real-life example: int is counting whole apples; float is weighing flour on a kitchen scale.
a, b = 10, 3
print(a + b, a / b, a // b, a % b, a ** b)Python Casting
Casting converts one type to another: int(), float(), str(), bool().
Wrap risky conversions in try/except when reading user input.
Real-life example: Casting is like converting rupees to dollars — same value, different format for the receiver.
text = "42"
number = int(text)
print(number + 8)
value = str(99)
print("Score: " + value)