Organized in logical progression โ each topic builds on the previous one. Includes what to learn, why it matters, and real-world use cases.
Goal: Write simple scripts and understand syntax.
- Installing Python (via Anaconda or official installer)
- Running Python: IDLE, Jupyter, VS Code, terminal
print()
,input()
, comments
๐ก Use Case: Hello World, user interaction
- Variables (no declaration needed)
- Basic types:
int
,float
,str
,bool
,None
- Type checking:
type()
- Type conversion:
int("5")
,str(3.14)
๐ก Use Case: Storing user input, calculations
- Arithmetic:
+
,-
,*
,/
,//
,%
,**
- Comparison:
==
,!=
,>
,<
- Logical:
and
,or
,not
- Assignment:
=
,+=
,-=
๐ก Use Case: Conditions, math operations
if
,elif
,else
- Nested conditions
- Ternary operator:
x = "even" if num % 2 == 0 else "odd"
๐ก Use Case: Decision-making in programs
for
loop:for i in range(5):
while
loop:while x < 10:
break
,continue
,pass
- Looping through strings, lists
๐ก Use Case: Processing lists, repeating tasks
- String creation, quotes (
'
,"
,'''
) - Indexing & slicing:
s[0]
,s[1:4]
- Methods:
.upper()
,.lower()
,.split()
,.join()
,.strip()
- f-strings:
f"Hello {name}!"
๐ก Use Case: Text processing, formatting output
๐ This topic has been expanded into four detailed notebooks!
- 7a. Lists
[]
: The most common, general-purpose, and mutable collection.- 7b. Tuples
()
: Immutable collections, used for fixed data.- 7c. Sets
{}
: For storing unique items and performing mathematical set operations.- 7d. Dictionaries
{}
: For storing data as key-value pairs.
๐ Master: list comprehensions, dictionary methods, set operations, and when to use each type.
- Defining:
def greet(name):
- Parameters & arguments
return
vsprint
- Default arguments:
def func(x=5):
- Keyword arguments:
func(name="Ali", age=25)
๐ก Use Case: Reusable code blocks
- Local vs Global variables
global
keyword- LEGB rule (Local โ Enclosing โ Global โ Built-in)
โ ๏ธ Avoid global variables when possible
- Common functions:
len()
,sum()
,min()
,max()
,sorted()
,enumerate()
,zip()
- Importing modules:
import math
,from datetime import datetime
- Standard library:
os
,sys
,json
,random
๐ก Use Case: File handling, date/time, randomness
- Reading/writing text files:
open("file.txt", "r")
- Context manager:
with open(...) as f:
- Working with JSON:
json.load()
,json.dump()
๐ก Use Case: Save/load data, config files
try
,except
,else
,finally
- Handling specific errors:
ValueError
,FileNotFoundError
- Raising errors:
raise ValueError("Invalid input")
๐ก Use Case: Make programs robust
class Person:
,__init__()
constructor- Creating objects:
p = Person("Ali")
- Instance variables & methods
self
explained
๐ก Use Case: Modeling real-world entities (User, Car, Document)
Concept | Explanation | Example |
---|---|---|
Encapsulation | Hide data using _private or __very_private |
self.__salary |
Inheritance | Child class inherits from parent | class Student(Person): |
Polymorphism | Same method, different behavior | student.walk() vs teacher.walk() |
Abstraction | Hide complex logic | Use methods without knowing internals |
๐ก Use Case: Code reuse, clean architecture
__str__()
โstr(obj)
__repr__()
โ debug representation__len__()
โlen(obj)
__add__()
โobj1 + obj2
๐ก Make your classes behave like built-in types
- Use
@property
to control access - Avoid direct attribute access
@property
def age(self):
return self._age
๐ก Use Case: Validation, computed properties
- Creating your own modules (
mymodule.py
) __init__.py
for packages- Installing packages:
pip install requests
๐ก Use Case: Organize large projects
- First-class functions: pass functions as arguments
lambda
:square = lambda x: x**2
map()
,filter()
,reduce()
- List/dict/set comprehensions (advanced)
๐ก Use Case: Data transformation, clean code
iter()
,next()
yield
vsreturn
- Memory-efficient:
def fib(): yield ...
๐ก Use Case: Large datasets, streaming data
@decorator
syntax- Create your own: timing, logging
- Accept arguments:
@retry(attempts=3)
def timer(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
print(f"Time: {time.time()-start}s")
return result
return wrapper
๐ก Use Case: Logging, caching, authentication
with open() as f:
- Create your own:
__enter__
,__exit__
@contextmanager
decorator
๐ก Use Case: Safe resource handling (files, DB connections)
- Define custom exceptions:
class InsufficientFundsError(Exception): pass
๐ก Use Case: Domain-specific errors
requests
: HTTP callsjson
,csv
: Data formatsos
,shutil
: File systemdatetime
: Date/timecollections
:defaultdict
,Counter
,namedtuple
๐ก Use Case: Real-world scripting and automation
- Project structure (
pyproject.toml
,src/
) - Building (
build
package) - Uploading (
twine
package)
๐ก Use Case: Distribute your code for others to
pip install
python -m venv myenv
source myenv/bin/activate
(Linux/Mac) ormyenv\Scripts\activate
(Windows)pip install
,pip freeze > requirements.txt
๐ก Use Case: Isolate project dependencies
Library | Purpose |
---|---|
numpy |
Numerical computing |
pandas |
Data analysis |
matplotlib/seaborn |
Data visualization |
requests |
Web APIs |
flask/fastapi |
Web development |
pytest |
Testing |
jupyter |
Interactive notebooks |
- PEP 8 (code style)
- Docstrings:
"""Explain function here"""
- Type hints:
def func(x: int) -> str:
- Writing clean, readable code
- Unit testing with
unittest
orpytest
๐ A detailed notebook for this topic,
27_Best_Practices.ipynb
, is available in the05_Next_Steps
folder!
- To-Do List App (CLI) โ Use lists, files
- Contact Book โ Use dictionaries, JSON
- Calculator โ Functions, error handling
- Web Scraper โ
requests
,BeautifulSoup
- Blog System โ Classes, file handling
- Quiz Game โ OOP, files, loops
Resource | Link |
---|---|
Official Python Docs | https://docs.python.org |
Real Python (Tutorials) | https://realpython.com |
Automate the Boring Stuff | https://automatetheboringstuff.com |
Corey Schafer (YouTube) | https://youtube.com/c/Coreyms |
W3Schools Python | https://w3schools.com/python |
LeetCode / HackerRank | Practice coding problems |
Week | Focus |
---|---|
1-2 | Basics: variables, loops, strings, lists |
3 | Functions, file handling, error handling |
4 | Dictionaries, sets, comprehensions |
5 | OOP: classes, inheritance, methods |
6 | Advanced: decorators, generators, context managers |
7 | Projects & libraries (requests , json , os ) |
8 | Virtual envs, best practices, type hints |