Python Beginner Handbook
Leeting Yan
Python is simple to learn, expressive to write, and powerful enough to build systems of any scale β from automation scripts to backend APIs and machine learning pipelines.
This handbook contains 20 concise, developer-friendly chapters, each focusing on practical understanding and working examples.
Chapter 1 β What Is Python & Why It Matters
Python is a high-level, cross-platform, readable language created in 1991.
Its design goals:
- readability
- developer productivity
- βbatteries-includedβ standard library
- large ecosystem of packages
Python powers:
- AI/ML (PyTorch, TensorFlow)
- Web APIs (FastAPI, Django)
- Automation & scripting
- DevOps tools
- Data pipelines
- Education
Python is often the best first language because concepts transfer well to other languages.
Chapter 2 β Installing Python & Setting Up Your Environment
Install Python
macOS
brew install python
Ubuntu
sudo apt install python3 python3-pip
Windows
Download from https://python.org
Create a project folder
mkdir myproject
cd myproject
Virtual environments
python3 -m venv env
source env/bin/activate # Windows: env\Scripts\activate
Install packages
pip install requests
Chapter 3 β Running Python: Scripts & REPL
Run a file
python3 hello.py
Use the Python REPL
python3
>>> print("hello")
Great for experimenting.
Use ipython (recommended)
pip install ipython
ipython
Chapter 4 β Variables, Expressions & Types
Python uses dynamic typing:
name = "Birdor"
age = 12
price = 19.99
active = True
Common types
strintfloatboollistdictsettuple
String formatting
print(f"Welcome, {name}!")
Chapter 5 β Control Flow (if, for, while)
If statements
if age >= 18:
print("Adult")
else:
print("Minor")
For loops
for item in ["a", "b", "c"]:
print(item)
While loops
n = 5
while n > 0:
print(n)
n -= 1
Chapter 6 β Functions
Basic function
def greet(name):
return f"Hello, {name}"
Default arguments
def connect(host="localhost"):
print(host)
Multiple return values
def stats(a, b):
return a + b, a * b
s, m = stats(3, 4)
Chapter 7 β Modules & Importing
Import built-in modules
import math
print(math.sqrt(9))
Custom module
utils.py
def add(a, b):
return a + b
main.py
import utils
print(utils.add(3, 5))
Chapter 8 β Lists & List Comprehensions
Lists
users = ["A", "B", "C"]
Append / remove
users.append("D")
users.remove("B")
List comprehension (Pythonic)
squares = [x*x for x in range(10)]
Chapter 9 β Dictionaries
Basic dictionary
profile = {"name": "Ada", "age": 25}
Access
print(profile["name"])
Iterate
for key, value in profile.items():
print(key, value)
Dictionaries are essential for manipulating JSON-like data.
Chapter 10 β Strings & Text Processing
Common operations
text = "birdor python"
print(text.upper())
print(text.split())
print("python" in text)
f-strings
name = "Birdor"
print(f"Welcome, {name}")
Joining lists
"-".join(["a", "b", "c"])
Chapter 11 β File Handling
with open("data.txt") as f:
content = f.read()
Write:
with open("log.txt", "w") as f:
f.write("hello\n")
JSON:
import json
data = json.load(open("data.json"))
Chapter 12 β Exceptions & Error Handling
Try / except
try:
x = 1 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
Finally
try:
f = open("data.txt")
finally:
f.close()
Chapter 13 β Classes & Object-Oriented Python
class User:
def __init__(self, name):
self.name = name
def hello(self):
return f"Hello, {self.name}"
u = User("Birdor")
print(u.hello())
Use classes when organizing behaviors + data.
Chapter 14 β Modules, Packages & Project Structure
Typical structure:
myapp/
app/
__init__.py
models.py
views.py
utils.py
tests/
main.py
__init__.py makes a folder a Python package.
Chapter 15 β Virtualenv / Pip / Poetry
pip + venv
pip install requests
pip freeze > requirements.txt
Poetry (recommended)
pip install poetry
poetry init
poetry add requests
Creates isolated envs automatically.
Chapter 16 β Testing with pytest
Install:
pip install pytest
test_add.py
def add(a, b):
return a + b
def test_add():
assert add(1, 2) == 3
Run:
pytest
Chapter 17 β Pythonic Code & Best Practices
Use list comprehension
[x*x for x in items]
Use context managers
with open("x.txt") as f:
pass
Use meaningful names
Avoid:
a, b, c
Use:
user_id, price, items
Follow PEP 8
Auto-format with:
pip install black
black .
Chapter 18 β AsyncIO & Concurrency (Beginner Safe)
Async example
import asyncio
async def task():
print("Running...")
await asyncio.sleep(1)
asyncio.run(task())
Great for:
- network I/O
- API servers (FastAPI)
- bots and crawlers
Not ideal for CPU-heavy tasks.
Chapter 19 β A Mini Project: CLI Tool
weather.py
import requests
import sys
def weather(city):
res = requests.get(f"https://wttr.in/{city}?format=3")
print(res.text)
if __name__ == "__main__":
weather(sys.argv[1])
Run:
python3 weather.py London
This project teaches:
- CLI arguments
- HTTP requests
- Modules
- Packaging
Chapter 20 β Where to Go Next
Recommended next steps:
Web development
- FastAPI
- Flask
- Django
Data science
- NumPy
- Pandas
- Jupyter
- Matplotlib
Machine learning
- PyTorch
- TensorFlow
Automation & DevOps
- Ansible
- Fabric
- Selenium
Packaging & distribution
- Poetry
- Docker
- PyInstaller
Python is a language that grows with you β from small scripts to full systems.
Final Words
Python succeeds because it stays simple, readable, friendly, and practical.
Itβs an excellent first language, a reliable tool for professionals, and a foundation for AI and cloud-native workflows.
Welcome to the Python ecosystem β and enjoy exploring it with clarity and confidence.