Write More Pythonic Code
Learning Path ⋅ Skills: Zen of Python, PEP 8, List Comprehensions, Application Layouts, Refactoring, Duck Typing, Type Checking, Type Hints, Protocols, Code Documentation, MkDocs, Code Quality, Pylint
In this learning path, you’ll learn to write cleaner, more Pythonic code. You’ll start with the Zen of Python and the PEP 8 conventions that encode it, then measure code quality, structure projects, and refactor what got complicated.
From there you’ll work through duck typing, type hints, static type checking, and protocols, and finish by documenting your projects with docstrings and MkDocs.
Write More Pythonic Code
Learning Path ⋅ 16 Resources
Python Philosophy and Style
Pythonic code starts with knowing what Python’s designers were aiming for. You’ll explore the Zen of Python, learn the PEP 8 conventions that encode it, and put both to work writing idiomatic loops and comprehensions. Everything later in the path builds on this shared sense of what good Python looks like.
Course
Tapping Into the Zen of Python
Explore the Zen of Python and its 19 guiding principles for writing readable, practical code. Learn its history, jokes, and meaning.
Interactive Quiz
What Exactly Is the Zen of Python?
Course
Writing Idiomatic Python
What are the programming idioms unique to Python? This course is a short overview for people coming from other languages and an introduction for beginners to the idiomatic practices within Python. You'll cover truth values, looping, DRY principles, and the Zen of Python.
Course
Writing Beautiful Pythonic Code With PEP 8
Learn how to write high-quality, readable code by using the Python style guidelines laid out in PEP 8. Following these guidelines helps you make a great impression when sharing your work with potential employers and collaborators. This course outlines the key guidelines laid out in PEP 8.
Interactive Quiz
How to Write Beautiful Python Code With PEP 8
Course
How to Write Pythonic Loops
See how you can make your loops more Pythonic if you're coming to Python from a C-style language. You'll learn how you can get the most out of using range(), xrange(), and enumerate(). You'll also see how you can avoid having to keep track of loop indexes manually.
Course
Using List Comprehensions Effectively
This short course breaks down Python list comprehensions for you step by step. See how Python's comprehensions can be transformed from and to equivalent "for"-loops so you'll know exactly what's going on behind the scenes.
Code Quality and Structure
Style conventions tell you what good code looks like, but they don’t tell you whether your project has drifted. Now you’ll measure quality with linters like Pylint, lay out projects so they stay navigable as they grow, and refactor the parts that got complicated. These are the habits that keep a codebase readable after the first draft.
Course
Managing and Measuring Python Code Quality
Master Python code quality tools like linters, formatters, type checkers, and profilers to measure, manage, and improve the code you write.
Interactive Quiz
Python Code Quality: Best Practices and Tools
Course
Writing Cleaner Python Code With PyLint
See how to install and set up the PyLint code linter tool. You'll learn why you should use code linters like PyLint, Flake8, PyFlakes, or other static analysis tools—and how they can help you write cleaner and more Pythonic code.
Course
Structuring a Python Application
This course is a reference guide to common Python application layouts and project structures for command-line applications, web applications, and more.
Interactive Quiz
Python Application Layouts: A Reference
Tutorial
Refactoring Python Applications for Simplicity
Learn how to refactor your Python application to be simpler and more maintainable and have fewer bugs. You'll cover code metrics, refactoring tools, and common anti-patterns.
Duck Typing, Type Checking, and Protocols
Clean, well-structured code still needs to be clear about what it expects. Python’s answer starts loose with duck typing, then gets progressively more explicit through type hints, static type checking, and protocols that let you name a shape without inheriting from it. You’ll finish by annotating functions that can return more than one type.
Course
Getting to Know Duck Typing in Python
Learn about duck typing in Python---a type system based on an object's behavior rather than inheritance. By taking advantage of duck typing, you can create flexible and decoupled sets of Python classes that work together or independently.
Interactive Quiz
Duck Typing in Python: Writing Flexible and Decoupled Code
Course
Python Type Checking
In this course, you'll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way. Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop your code more efficiently.
Interactive Quiz
Python Type Checking
Course
Exploring Protocols in Python
Learn how Python's protocols improve your use of type hints and static type checkers in this practical video course.
Interactive Quiz
Python Protocols: Leveraging Structural Subtyping
Course
Using Type Hints for Multiple Return Types in Python
Learn how to define multiple return types using type hints in Python. This course covers working with single or multiple pieces of data, defining type aliases, and performing type checking using a third-party static type checker tool.
Interactive Quiz
How to Use Type Hints for Multiple Return Types in Python
Documentation
Type hints tell other developers what your code expects, but they don’t explain why it exists. Documentation closes that gap. You’ll write docstrings that carry their weight, then publish a full project documentation site with MkDocs.
Course
Documenting Code in Python
Whether you're documenting a small script or a large project, whether you're a beginner or seasoned Pythonista, this guide will cover everything you need to know.
Interactive Quiz
Documenting Python Code: A Complete Guide
Course
Building Python Project Documentation With MkDocs
Learn how to build professional documentation for a Python package using MkDocs and mkdocstrings. These tools allow you to generate nice-looking and modern documentation from Markdown files and, more importantly, from your code's docstrings.
Test Your Knowledge
You’ve made it through the entire path! In the wrap-up quiz below, you’ll revisit the most important ideas about the Zen of Python, PEP 8, code quality, type checking, and documentation. Use it to spot any topics that still feel rusty before moving on.
Interactive Quiz
Write More Pythonic Code
Test your understanding of Pythonic code: the Zen of Python, PEP 8, code quality, type checking, and documentation in 20 questions.
Congratulations on completing this learning path! You’ve learned to write clean, idiomatic Python using PEP 8, code quality tools, type hints and protocols, and documentation best practices.
Continue your intermediate Python journey with the next learning path:
Learning Path
Testing and Continuous Integration
10 Resources ⋅ Skills: Unit Testing, Doctest, Mock Object Library, Pytest, Continuous Integration, Docker, Code Quality, GitHub Actions, Software Testing, CI/CD
You might also be interested in these related learning paths:
Got feedback on this learning path?
Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!