Variables store data.
name = "Hello"
age = 20
price = 99.99✅ Rules:
- 🔤 Start with a letter or
_ - 🔢 Cannot start with a number
- 🚫 No spaces
- 🔠 Case-sensitive (
name≠Name) - ❌ Don't use keywords (
if,for,class)
| Data Type | Example |
|---|---|
| 🔢 int | 10 |
| 💰 float | 10.5 |
| 🔤 str | "Hello" |
| ✅ bool | True |
| 📋 list | [1,2,3] |
| 📦 tuple | (1,2,3) |
| 🎯 set | {1,2,3} |
| 📖 dict | {"a":1} |
| ⚡ complex | 2+3j |
| 🚫 NoneType | None |
print(type(10))Convert one data type to another.
int("10")
float("10.5")
str(100)
bool(1)
list("Python")
tuple([1,2])
set([1,2,2])
dict([("a",1)])name = input("Enter Name: ")
age = int(input("Enter Age: "))
price = float(input("Enter Price: "))+
-
*
/
%
//
**==
!=
>
<
>=
<=and
or
not=
+=
-=
*=
/=is
is notin
not inif op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
elif op == "/":
print(a / b)print()
input()
type()
len()
int()
float()
str()
bool()
list()
tuple()
set()
dict()
range()
id()a, b, c = 10, 20, 30
x = y = z = 100Swap Variables
a, b = b, aletters = ["P","y","t","h","o","n"]
print("".join(letters))student = {
"name": "Hit",
"age": 20
}Keys
student.keys()Values
student.values()Items
student.items()numbers = [10,20,30]data = (10,20,30)data = {10,20,30}No duplicate values.
True
False- 📦 Variable → Stores data
- 🔤
str→ Text - 🔢
int→ Whole number - 💰
float→ Decimal number - ✅
bool→ True/False - 📋
list→ Ordered, Mutable - 📦
tuple→ Ordered, Immutable - 🎯
set→ Unique values - 📖
dict→ Key : Value - 🔄 Type Casting → Change data type
- ⌨️
input()→ Take user input - 🖨️
print()→ Display output - 🏷️
type()→ Check data type
# Variable
x = 10
# Input
name = input()
# Integer Input
age = int(input())
# Float Input
price = float(input())
# Print
print(name)
# Data Type
type(x)
# Type Casting
int()
float()
str()
bool()
list()
tuple()
set()
dict()
# Swap
a, b = b, a⭐ Golden Rule:
Declare → Input → Process → Output