Learn Python: Complete Roadmap
A structured path for programmers new to Python (or switching from another language) covering environment setup through advanced features, with milestone projects to verify real understanding at each stage.
study, coding, productivity
by Morris
Environment Setup
Get a clean, professional Python environment before writing a single line of code. Skipping this phase causes dependency disasters later.
- Install Python from python.org - NOT the system Python on macOS/Linux
- Install pyenv to manage multiple Python versions side-by-side
- Create a virtual environment (venv) for EVERY project - this is non-negotiable
- Learn pip: install packages, freeze dependencies, and understand what goes in requirements.txt
- Set up VS Code with the Python extension, Black formatter, and Ruff linter
- Explore the IPython REPL for fast experimentation
Core Types and Syntax
Python's type system has specific behaviors that trip up beginners. Understand mutability before writing any real code - it prevents weeks of confusing bugs.
- Understand that everything in Python is an object - including functions, classes, and None
- Master Python's built-in types: int, float, str, bool, bytes, None - and how they differ from other languages
- Learn mutability - the single most important concept for avoiding Python bugs
- Use f-strings for all string formatting - avoid % formatting and .format()
- Understand string slicing - Python's powerful sequence access syntax
- Learn Python truthiness and the difference between == and is
Control Flow and Functions
Python has elegant patterns for iteration and function design that are fundamentally different from C-style languages. Learning them early makes everything easier.
- Replace range(len()) with enumerate() and zip() for cleaner iteration
- Learn the for/else clause - Python's hidden gem for search loops
- Master function signatures: positional, keyword, *args, **kwargs, and keyword-only arguments
- Understand the LEGB scope rule: Local, Enclosing, Global, Built-in
- Write pure functions by default - same inputs always produce same outputs, no side effects
- Understand lambda limitations - use def for anything beyond a one-liner expression
Data Structures
Python's four core collections each have a distinct purpose and performance profile. Choosing the wrong one is the most common source of slow Python code.
- Learn the decision framework: list vs tuple vs dict vs set
- Understand O(1) set/dict lookup vs O(n) list scan and when it matters
- Use dict insertion order (guaranteed since Python 3.7) and dict methods
- Preview collections.Counter and defaultdict for common dict patterns
- Practice common list operations: append, extend, pop, remove, sort vs sorted
Pythonic Code
Writing Python that looks and feels like Python - not translated C or Java. Idiomatic Python is shorter, faster, and easier to read.
- Replace for-loops that build lists with list comprehensions
- Use dict comprehensions and set comprehensions for building collections
- Master tuple unpacking and the star operator for elegant assignments
- Use ''.join() instead of string concatenation in loops
- Read PEP 8 and internalize the most important naming and spacing rules
- Read the Zen of Python and understand how it guides design decisions
Modules and Packages
Understanding how Python's import system works prevents confusing ImportErrors and helps you structure projects correctly from the start.
- Learn the three import forms and when to use each
- Always include the if __name__ == '__main__' guard in scripts
- Understand Python package structure with __init__.py
- Write and use a requirements.txt file properly for reproducible installs
- Use python-dotenv to manage environment variables - never hardcode secrets
Object-Oriented Python
Python supports OOP but is not a pure OOP language. Know when classes genuinely help and when they add unnecessary complexity - Python is not Java.
- Understand class attributes vs instance attributes - a common source of bugs
- Implement key dunder methods: __str__, __repr__, __eq__, __hash__
- Use @property for computed attributes and controlled attribute access
- Replace manual __init__ boilerplate with @dataclass
- Know when NOT to use a class - Python is not Java
Error Handling and File I/O
Robust Python programs handle failures gracefully. Learn the right patterns now and avoid 'works on my machine' bugs in production.
- Always use the 'with' statement for file operations - it guarantees the file is closed
- Always specify encoding='utf-8' when opening text files
- Use try/except/else/finally correctly - never use bare except
- Define custom exceptions for your application's error domain
- Use pathlib.Path instead of os.path for all file system operations
- Use the csv module for CSV files instead of manual string splitting
The Standard Library
Python's 'batteries included' standard library can replace dozens of third-party packages. Learn these modules and you'll write less code and have fewer dependencies.
- Master collections: Counter, defaultdict, deque, and OrderedDict
- Use itertools for lazy, memory-efficient iteration
- Use the logging module instead of print statements in any code beyond simple scripts
- Learn the json module for serialization and deserialization
- Use argparse to build proper command-line interfaces
Advanced Python
Generators, decorators, type hints, and closures are where Python's expressive power shows. These patterns appear constantly in production codebases.
- Understand generators and yield for memory-efficient processing of large data
- Write decorators with functools.wraps to add behavior to functions cleanly
- Use functools.lru_cache and functools.partial for memoization and partial application
- Add type hints to all new code and run mypy to catch type errors
- Understand closures - functions that capture variables from their enclosing scope
Testing and Code Quality
Tests are the proof that your code works. Learn pytest patterns once and they'll serve you for the rest of your Python career.
- Install pytest and write your first tests using the describe/it pattern
- Use pytest fixtures for test setup and shared resources
- Use @pytest.mark.parametrize to test many cases without duplicating code
- Mock external dependencies with unittest.mock to test in isolation
- Measure test coverage with pytest-cov and aim for meaningful, not 100%, coverage
- Run Black, Ruff, and mypy as a pre-commit quality gate
Capstone Project
Apply everything you've learned in a complete, deployable project. The choice of track determines the real-world domain. Do not skip this - building something is how knowledge becomes skill.
- Choose your project track based on your goal
- Structure the project properly before writing any business logic
- Add type hints to all public functions and verify with mypy
- Write tests for all business logic functions (aim for 80%+ coverage on the src/ directory)
- Replace all print() debugging with proper logging and document the usage in README
- Deploy or distribute the project so someone else can actually use it