🐍
PYTHON PROGRAMMING
Complete Study Notes | Beginner to Intermediate
Variables • Functions • OOP • Libraries • File I/O • Exam Tips
📚 8 Topics 💡 30+ Examples ⚡ Key Tips 📝 Exam Ready
1. INTRODUCTION TO PYTHON
Python is a high-level, interpreted, general-purpose programming language. Created by Guido van
Rossum in 1991, it emphasises code readability and simplicity, making it the world's most popular
language for beginners and professionals alike.
Why Python?
● Simple, English-like syntax — easy to learn and write
● Interpreted — runs line by line; no compilation needed
● Cross-platform — runs on Windows, macOS, Linux
● Huge standard library + thousands of packages (pip)
● Used in Web Dev, AI/ML, Data Science, Automation, Cloud & IoT
2. VARIABLES & DATA TYPES
A variable is a named container that stores data. In Python, you do NOT declare types — Python infers
them automatically (dynamic typing).
Data Type Example Description
int age = 25 Whole numbers (no decimals)
float gpa = 3.75 Decimal / real numbers
str name = "Alice" Text (sequence of characters)
bool passed = True True or False only
list marks = Ordered, mutable collection
[90,85,78]
dict info = Key-value pairs (hash map)
{"key":"val"}
tuple coords = (10, 20) Ordered, immutable collection
© CS Study Hub | Python Programming Notes | Share & Learn — Not for Resale
, 🐍 Python Programming — Complete Study Notes | Page
set ids = {1, 2, 3} Unique unordered elements
Variable Examples:
# Assigning variables
name = "Alice" # string
age = 20 # integer
gpa = 3.85 # float
is_enrolled = True # boolean
# Type checking
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
# Multiple assignment
x, y, z = 10, 20, 30
💡 PRO TIP — Naming Conventions
Use snake_case for variables (my_variable), PascalCase for classes (MyClass). Variable names
are case-sensitive: age ≠ Age ≠ AGE. Avoid using Python reserved keywords like list, print, or input
as variable names.
3. CONTROL FLOW — if / elif / else & Loops
3.1 Conditional Statements
Python uses indentation (4 spaces) instead of curly braces to define code blocks.
score = 75
if score >= 90:
print("A — Distinction")
elif score >= 75:
print("B — Merit") # This runs
elif score >= 60:
print("C — Pass")
else:
print("F — Fail")
3.2 Loops
for Loop while Loop
Used when you know how many times to repeat. Used when condition decides when to stop.
for i in range(5): count = 0
print(i) # 0,1,2,3,4 while count < 5:
print(count)
fruits = ['apple','mango'] count += 1
for f in fruits:
print(f) # break exits loop early
© CS Study Hub | Python Programming Notes | Share & Learn — Not for Resale