🐍 Python Mastery Guide: Beginner to Advanced
PART 1: Getting Started
What is Python?
Python is a popular, high-level programming language known for its simplicity and readability. It's used
in web development, data analysis, automation, artificial intelligence, and more.
Installing Python
• Visit python.org and download the latest version.
• Use an IDE like VS Code, PyCharm, or simple editors like IDLE.
Running Your First Script
print("Hello, world!")
Save this as hello.py and run it in terminal:
python hello.py
PART 2: Python Basics
Variables and Data Types
x = 5 # int
y = 3.14 # float
name = "Alice" # str
is_happy = True # bool
Input and Output
name = input("What is your name? ")
print("Hello,", name)
Comments
# This is a comment
1
Math Operators
+, -, *, /, //, %, **
PART 3: Control Flow
If Statements
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Boolean Logic
and, or, not
PART 4: Loops
While Loop
count = 0
while count < 5:
print(count)
count += 1
For Loop
for i in range(5):
print(i)
Loop Control
break, continue
2
PART 5: Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Bob"))
Lambda
square = lambda x: x * x
PART 6: Data Structures
List
fruits = ["apple", "banana"]
Tuple
point = (3, 4)
Set
unique = {1, 2, 3}
Dictionary
person = {"name": "Alice", "age": 25}
List Comprehension
squares = [x*x for x in range(10)]
PART 7: Working with Files
with open("file.txt", "r") as f:
content = f.read()
3
PART 8: Error Handling
try:
1 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("Done")
PART 9: Modules and Packages
import math
print(math.sqrt(16))
Install with pip:
pip install package_name
PART 10: OOP (Object-Oriented Programming)
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
print(self.name + " makes a sound")
cat = Animal("Whiskers")
cat.speak()
PART 11: Advanced Topics
• Decorators
• Generators
• Recursion
• Closures
4
PART 12: Python in the Real World
• Web scraping with requests , BeautifulSoup
• APIs with requests
• Data analysis with pandas , numpy
• Automation (scripts, file renaming)
• Web apps ( Flask , FastAPI )
PART 13: Practice + Projects
Beginner Projects
• Calculator
• To-do app
• Guess the number
Intermediate Projects
• Expense tracker
• Weather app using API
• File organizer
Advanced Ideas
• Chatbot
• Web scraper with database
• Portfolio website with Flask
Use this guide as your offline reference and add notes or code examples as you learn!