Learn Python: Complete Roadmap

A structured learning path from environment setup to production-quality Python code. Built to establish good habits from day one and avoid the mistakes that take months to unlearn.

study, coding, productivity

by Morris

Environment Setup

Get the foundation right before writing a single line of code. Bad environment habits cause problems that are invisible until they are very expensive.

  • Install Python 3.12+ from python.org and never use the system Python on macOS or Linux
  • Install pyenv to manage multiple Python versions cleanly
  • Create and activate a virtual environment before every project - this is non-negotiable
  • Understand pip: install packages, freeze requirements, and restore from requirements.txt
  • Set up VS Code with the Python extension, or install PyCharm Community Edition
  • Install Black (formatter) and Ruff (linter) and configure your editor to run them on save
  • Learn to use the Python REPL for quick experiments - it is the fastest feedback loop available

Core Types and Syntax

Python's type system is simple but has specific behaviors that surprise everyone at least once.

  • Understand that everything in Python is an object, including integers and functions
  • Know the built-in types: int, float, str, bool, bytes, NoneType
  • Understand mutability: this is the most common source of Python bugs for beginners
  • Master f-strings for all string formatting
  • Understand Python string slicing: indexing, negative indexes, step
  • Understand truthiness: know which values are falsy in Python
  • Understand the difference between == (equality) and is (identity)
  • Know common string methods: .strip(), .split(), .join(), .replace(), .startswith(), .endswith(), .lower(), .upper()

Control Flow and Functions

How Python moves through code and how to structure reusable logic. The function design skills here matter more than the syntax.

  • Write if/elif/else blocks and understand Python uses indentation instead of braces
  • Use for loops with range(), enumerate(), and zip() - avoid manual index tracking
  • Understand the for/else construct: else runs only if the loop completed without hitting break
  • Write functions with positional args, keyword args, default values, *args, and **kwargs
  • Understand the LEGB scope rule: Local, Enclosing, Global, Built-in
  • Write pure functions: same input always produces same output, no side effects
  • Use lambda functions only for short throwaway functions - prefer named functions for anything complex
  • Build a number guessing game: random number, user input loop, input validation, feedback, attempt counter

Data Structures

Python's four core structures. Choosing the right one is the difference between clear and confusing code.

  • Master lists: creation, indexing, slicing, appending, removing, and sorting
  • Understand tuples: immutable sequences, when to use instead of lists
  • Master dictionaries: creation, access with .get(), iteration, updating, and common patterns
  • Understand sets: uniqueness, O(1) membership testing, and set operations
  • Internalize the structure selection rule: list for ordered sequences, dict for key-value lookups, set for unique membership, tuple for fixed-structure records
  • Understand that Python dicts preserve insertion order since Python 3.7
  • Know the performance difference: list membership test is O(n), set/dict lookup is O(1)

Pythonic Code

Writing Python the way Python is meant to be written. These patterns are not optional extras - they are the standard.

  • Write list comprehensions to replace verbose for-loop-append patterns
  • Write dict and set comprehensions
  • Use tuple unpacking and extended unpacking with *
  • Use enumerate() whenever you need both the index and the value in a loop
  • Use zip() to iterate multiple sequences in parallel without index juggling
  • Read PEP 8: the official Python style guide - understand the rules before you decide which to follow
  • Run 'import this' in the Python REPL and read the Zen of Python - it shapes how to make trade-offs
  • Use context managers (with statement) for any resource that needs cleanup
  • Avoid this: building a string by concatenating in a loop - use ''.join() instead

Modules and Packages

How Python code is organized, shared, and imported. Understanding this prevents import errors and project structure confusion.

  • Understand that any .py file is a module and any directory with __init__.py is a package
  • Know all import forms and when to use each
  • Understand and always use the __name__ == '__main__' guard in script files
  • Create a multi-file project: split a program into at least 3 modules and import between them
  • Understand relative vs absolute imports inside a package
  • Know how to structure a Python project: src layout vs flat layout, where to put tests
  • Know pip commands beyond install: pip list, pip show, pip uninstall, pip install --upgrade

Object-Oriented Python

Classes are a tool, not a requirement. Learn them properly and then learn when not to use them.

  • Understand why OOP exists: bundling related data and behavior, and modeling real-world entities
  • Define a class with __init__ and instance methods, understanding self
  • Understand class attributes vs instance attributes
  • Implement inheritance and understand super()
  • Learn the key dunder methods: __str__, __repr__, __len__, __eq__, __hash__, __contains__
  • Use @property to create computed attributes with optional validation
  • Learn dataclasses: they generate __init__, __repr__, and __eq__ automatically for data-holding classes
  • Know when NOT to use classes: Python is not Java - a module with functions is often the right answer

Error Handling and File I/O

Programs that crash on unexpected input are not finished. Error handling is correctness, not polish.

  • Read and write files using the with statement - always, never open() without with
  • Use the csv module to read and write CSV files instead of splitting strings manually
  • Handle exceptions with try/except/else/finally and catch specific exceptions, not bare except
  • Create custom exception classes for domain-specific errors
  • Understand when to catch exceptions vs when to let them propagate
  • Use pathlib.Path for all file path operations instead of os.path string joining

The Standard Library

Python ships with a large and excellent standard library. Most things you reach for a package to do already have a solution here.

  • Learn collections.Counter: count occurrences in any iterable in one line
  • Learn collections.defaultdict: a dict that creates a default value for missing keys automatically
  • Learn itertools: chain, product, combinations, permutations, groupby, islice
  • Learn datetime: parse dates, format them, calculate differences with timedelta
  • Learn json: serialize Python objects to JSON strings and back
  • Learn the logging module: use it instead of print() for anything beyond a quick script
  • Learn argparse: add command-line argument parsing to any script
  • Learn re (regular expressions): match patterns, extract groups, and replace in strings

Advanced Python

The features that separate readable, efficient Python from beginner Python. These unlock writing code that other developers want to read.

  • Understand generators: functions that yield values lazily instead of building a full list in memory
  • Write decorators: functions that wrap other functions to add behavior
  • Write a custom context manager using __enter__ and __exit__
  • Add type hints to all function signatures and key variables
  • Run mypy on a typed file and fix every error it reports
  • Understand closures in Python and how they interact with decorators and generators
  • Learn functools: partial, lru_cache, reduce, and wraps

Testing and Code Quality

Code without tests is a guess. These tools make your Python code provably correct and consistently formatted.

  • Install pytest and write your first test file
  • Use pytest fixtures for setup and teardown logic shared across tests
  • Parametrize tests to run the same test with multiple inputs
  • Mock external dependencies with unittest.mock so tests do not hit real APIs or databases
  • Use pytest-cov to measure code coverage and identify untested paths
  • Configure Black for automatic code formatting
  • Configure Ruff for fast linting: it replaces Flake8, isort, and many other tools
  • Run mypy in strict mode on your project and fix all type errors

Capstone Project

One real program that forces all the concepts to work together. Choose the track that matches your Python goal.

  • Choose your Python track and pick the matching capstone project
  • Plan the project structure before writing code: modules, data flow, external dependencies
  • Set up the project with venv, requirements.txt, and a .gitignore from the start
  • Add type hints to every function signature
  • Write tests for all business logic before or alongside writing the code
  • Use proper logging throughout instead of print statements
  • Handle all expected errors explicitly: bad user input, missing files, network failures
  • Run Black, Ruff, and mypy and fix every reported issue before considering the project done
  • Write a README explaining what the project does, how to install it, and how to use it
  • Share the project publicly: push to GitHub with a descriptive commit history