1 · What Is Python & Why Use It?

Python is a high‑level, dynamically typed, interpreted language known for its readability (PEP 20 “Zen of Python”), vast ecosystem, and “batteries‑included” standard library.

# Hello, world
print("Hello Py Universe 🚀")

2 · Installing Python & Managing Environments

2.1 Official Installers & Package Managers

Download from python.org (Windows/macOS) or use a system package manager:

# macOS — Homebrew
brew install python@3.12

# Windows — winget
winget install Python.Python.3.12

# Linux — APT
sudo apt install python3.12

2.2 Isolated Environments

Use venv (built‑in) or virtualenv for dependency isolation.

# create & activate
python3 -m venv .env
source .env/bin/activate   # *NIX
.env\Scripts\activate.bat  # Windows

2.3 Dependency Managers

3 · Syntax Basics & Core Data Types

3.1 Primitive Types

TypeLiteralsExample
BooleanTrue, Falsea = True
Integer42, 0xFFcount = 1_000
Float3.14, 1e‑3pi = 3.14159
String"hi", 'hi'msg = "Hello"

3.2 Collections

# Lists (mutable, ordered)
nums = [1, 2, 3]

# Tuples (immutable, ordered)
pt = (10, 20)

# Sets (unique members)
tags = {"python", "guide"}

# Dicts (key‑value)
user = {"id": 1, "name": "Ada"}

3.3 Control Flow

for n in nums:
    if n % 2 == 0:
        print(f"{n} is even")
    else:
        continue

while True:
    break

4 · Defining & Using Functions

4.1 Basics

def add(a: int, b: int) -> int:
    "Return sum of a and b."
    return a + b

4.2 Default & Keyword‑Only Args

def greet(name, *, punct="!"):
    print(f"Hello {name}{punct}")

4.3 First‑Class & Higher‑Order

funcs = [abs, len]
for f in funcs:
    print(f"Using {f.__name__}: {f(['hi'])}")

5 · Object‑Oriented Programming

5.1 Classes & Instances

class Vector:
    def __init__(self, x: float, y: float):
        self.x, self.y = x, y

    def __repr__(self):
        return f"Vector({self.x}, {self.y})"

    def magnitude(self) -> float:
        return (self.x**2 + self.y**2)**0.5

5.2 Inheritance & Polymorphism

class Animal:                  # base
    def speak(self):
        raise NotImplementedError

class Dog(Animal):             # derived
    def speak(self):
        return "Bark!"

pets: list[Animal] = [Dog()]
for p in pets:
    print(p.speak())  # dynamic dispatch

5.3 Data Classes

from dataclasses import dataclass

@dataclass
class Point:
    x: float
    y: float

6 · Modules, Packages & Imports

Every .py file is a module; a folder with __init__.py is a package. Import styles:

import math
from pathlib import Path
import numpy as np

Use __all__ to declare public API, and take advantage of namespace packages (no __init__.py) in modern tooling.

7 · Exceptions & Debugging

7.1 Try/Except

try:
    r = 1 / 0
except ZeroDivisionError as e:
    print("Bad math:", e)
finally:
    print("Cleanup")

7.2 Custom Exceptions

class ConfigError(Exception):
    """Raised for invalid config."""

7.3 Debugging Tools

8 · File I/O & Serialization

# Reading
with open("data.txt") as f:
    data = f.read()

# Writing
Path("out.txt").write_text("Hello")

# JSON
import json
blob = json.dumps({"ok": True}, indent=2)

# Pickle (⚠️ avoid untrusted data)
import pickle
payload = pickle.dumps(obj)

9 · Concurrency & Parallelism

9.1 Threads (vs GIL)

from threading import Thread

def worker(id):
    print(f"Thread {id}")

th = Thread(target=worker, args=(1,))
th.start(); th.join()

9.2 Multiprocessing

from multiprocessing import Pool
with Pool() as p:
    print(p.map(pow, [2,3,4], [5,5,5]))  # [32, 243, 1024]

9.3 Async IO

import asyncio, aiohttp

async def fetch_json(url):
    async with aiohttp.ClientSession() as s:
        async with s.get(url) as r:
            return await r.json()

json_data = asyncio.run(fetch_json("https://api.github.com"))

10 · Testing & Quality Assurance

# tests/test_math.py
import pytest
from guide import add

def test_add():
    assert add(2, 3) == 5

11 · Packaging & Distribution

# pyproject.toml (minimal)
[project]
name = "awesome‑pkg"
version = "0.1.0"
dependencies = ["requests"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Build & publish:

pip install build twine
python -m build
twine upload dist/*

12 · Standard Library Highlights

ModulePurpose
pathlibOO path manipulation.
datetimeDates, times, time zones (3.9 zoneinfo).
itertoolsLazily evaluated combinatorics.
dataclassesBoilerplate‑free data containers.
typingType hints; 3.10 | union.

13 · Idioms, PEP 8 & Tooling

14 · Further Reading & Learning Paths

Books & Docs:

Practice portals: LeetCode, HackerRank, Exercism.