Python conventions and best practices are commonly accepted guidelines, idioms, and patterns that help you write Python code that’s clear, consistent, and maintainable. Learn established approaches to code readability, Pythonic idioms, dependency and project management, testing, type hinting, error handling, resource management, logging, concurrency, refactoring, documentation, distribution, and more.
This is especially important as AI coding tools become increasingly capable of generating code but may not follow best practices when doing so.
Each guide stands on its own and provides focused examples, practical comparisons, and reusable patterns that you can apply right away to write more maintainable and consistent Python code.
Not sure which term you need? Describe what you’re trying to do, and Mentor AI will point you to the right entries.
classesGuidelines and best practices for using Python classes as an expert in OOP.
code formattingGuidelines and best practices for formatting your Python code.
code testingGuidelines and best practices for putting together a robust and flexible test suite for your Python code.
coding styleGuidelines and best practices that will help you code like an expert Pythonista.
commentsGuidelines and best practices for writing useful and relevant comments in Python.
comprehensionsGuidelines and best practices for leveraging the power of Python comprehensions
concurrencyGuidelines and best practices for writing concurrent code the right way in Python.
conditionalsGuidelines and best practices for writing reliable conditionals and making decisions in your Python code.
constantsGuidelines and best practices for using constants in your Python code.
dependency managementGuidelines and best practices for dependency management in Python.
distributionGuidelines and best practices for packaging, building, and distributing your Python projects.
docstringsGuidelines and best practices that will help you write good docstrings for your Python packages, modules, functions, and classes.
documentationGuidelines and best practices for writing great documentation for your Python projects.
exception handlingGuidelines and best practices for handling exceptions and errors in your Python code.
functionsGuidelines and best practices for writing robust functions in Python.
generator expressionsGuidelines and best practices for using generator expressions for memory-efficient data transformation.
importsGuidelines and best practices for leveraging the power of the Python import system.
loggingGuidelines and best practices for logging in Python.
loopsGuidelines and best practices for writing efficient and Pythonic loops.
object mutabilityGuidelines and best practices that will help you use mutable and immutable data types in Python.
optimizationGuidelines and best practices for optimizing your Python code.
project layoutGuidelines and best practices for effectively structuring and organizing your Python projects.
public API surfaceGuidelines and recommendations for using public and non-public names in your Python code.
Pythonic codeGuidelines and best practices to using language idioms and constructs that will make your code more Pythonic, faster, and more beautiful.
refactoringGuidelines and best practices for refactoring your Python code.
resource managementGuidelines and best practices for managing external resources, such as files, network connections, and similar, in Python.
securityGuidelines and best practices to help prevent security vulnerabilities in your Python code.
standard libraryGuidelines and best practices for using standard-library code in your Python programs.
third-party librariesGuidelines and best practices for choosing and using third-party libraries in your Python code.
type checkingGuidelines and best practices for leveraging type hints and static type checking in your Python code.
variablesGuidelines and best practices for using variables like an expert Python developer.