Python Basics — Day 2(Variables and Data Types)
Aspiring Full-Stack Developer | Python · Django · React · SQL | documenting my learning journey
Building skills in Python and full-stack development, with a focus on web apps and system design
Junior developer in training — Python, Django, React — preparing for a career in full-stack engineering
From Python basics to full-stack projects, sharing my progress as I grow into a developer
Future full-stack engineer | Learning in public: Python, APIs, Databases, and Web Development
01. What is a Variable?
A variable is like a label that stores data.
Use the
=operator to assign a value.
x = 10 # Integer (int)
y = 3.14 # Floating-point number (float)
name = "Sabin" # String (str)
is_ok = True # Boolean (bool)
02. Basic Data Types (Primitive Data Types)
🔹 Integer (int)
- Whole numbers without a decimal point
age = 25
print(age, type(age)) # 25 <class 'int'>
- Float (float)
- Numbers with decimals
pi = 3.14159
print(pi, type(pi)) # 3.14159 <class 'float'>
- String (str)
- A sequence of characters (use double
" "or single' 'quotes)
greeting = "Hello"
print(greeting, type(greeting)) # Hello <class 'str'>
- Boolean (bool)
- Represents
TrueorFalse
is_student = True
print(is_student, type(is_student)) # True <class 'bool'>
03. Variable Naming Rules
✅ Can contain letters, numbers, and underscores (_)
✅ Cannot start with a number
✅ Case-sensitive (Name ≠ name)
✅ Use descriptive names (recommended)
a = 10 # ❌ Not meaningful
student_age = 20 # ✅ Clear and descriptive
04. Type Casting
Convert between different data types.
# int → float
x = 10
print(float(x)) # 10.0
# float → int
y = 3.99
print(int(y)) # 3# str → int
num_str = "100"
print(int(num_str) + 1) # 101# int → str
age = 25
print("Age: " + str(age)) # Age: 25
05. Practice Examples
📝 Example 1: Print Variables
name = "Ian"
age = 20
height = 189
is_student = False
print("Name:", name)
print("Age:", age)
print("Height:", height)
print("Is student?", is_student)
📝 Example 2: Type Casting
a = "5"
b = 10
# Convert the string "5" into an int before adding
print(int(a) + b) # 15