PEP 8 Style Guide For Python Code Python.org

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 29

Scroll down to view the document on your mobile browser.
11/22/2018 PEP 8 -- Style Guide for Python Code | Python.orghttps://www.python.org/dev/peps/pep-0008/ 1/29Python (/) >>> Python Developer's Guide (/dev/) >>> PEP Index (/dev/peps/) >>> PEP 8 -- Style Guide for Python CodePEP  8  --  Style  Guide  for  Python  CodePEP: 8Title: Style Guide for Python CodeAuthor: Guido van Rossum <guido at python.org>, Barry Warsaw <barry at python.org>, Nick Coghlan <ncoghlan at gmail.com>Status: ActiveType: ProcessCreated: 05-Jul-2001Post-History: 05-Jul-2001, 01-Aug-2013ContentsIntroduction (#introduction)A Foolish Consistency is the Hobgoblin of Little Minds (#a-foolish-consistency-is-the-hobgoblin-of-little-minds)Code Lay-out (#code-lay-out)Indentation (#indentation)Tabs or Spaces? (#tabs-or-spaces)Maximum Line Length (#maximum-line-length)Should a Line Break Before or After a Binary Operator? (#should-a-line-break-before-or-after-a-binary-operator)Blank Lines (#blank-lines)Source File Encoding (#source-file-encoding)Imports (#imports)Module Level Dunder Names (#module-level-dunder-names)String Quotes (#string-quotes)Whitespace in Expressions and Statements (#whitespace-in-expressions-and-statements)Pet Peeves (#pet-peeves)Other Recommendations (#other-recommendations)When to Use Trailing Commas (#when-to-use-trailing-commas)Comments (#comments)Block Comments (#block-comments)Inline Comments (#inline-comments)Documentation Strings (#documentation-strings)
11/22/2018 PEP 8 -- Style Guide for Python Code | Python.orghttps://www.python.org/dev/peps/pep-0008/ 2/29Naming Conventions (#naming-conventions)Overriding Principle (#overriding-principle)Descriptive: Naming Styles (#descriptive-naming-styles)Prescriptive: Naming Conventions (#prescriptive-naming-conventions)Names to Avoid (#names-to-avoid)ASCII Compatibility (#ascii-compatibility)Package and Module Names (#package-and-module-names)Class Names (#class-names)Type Variable Names (#type-variable-names)Exception Names (#exception-names)Global Variable Names (#global-variable-names)Function and Variable Names (#function-and-variable-names)Function and Method Arguments (#function-and-method-arguments)Method Names and Instance Variables (#method-names-and-instance-variables)Constants (#constants)Designing for Inheritance (#designing-for-inheritance)Public and Internal Interfaces (#public-and-internal-interfaces)Programming Recommendations (#programming-recommendations)Function Annotations (#function-annotations)Variable Annotations (#variable-annotations)References (#references)Copyright (#copyright)Introduction (#id14)This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please seethe companion informational PEP describing style guidelines for the C code in the C implementation of Python [1] (#id8).This document and PEP 257 (/dev/peps/pep-0257) (Docstring Conventions) were adapted from Guido's original Python Style Guide essay, withsome additions from Barry's style guide [2] (#id9).This style guide evolves over time as additional conventions are identified and past conventions are rendered obsolete by changes in thelanguage itself.Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for thatproject.A Foolish Consistency is the Hobgoblin of Little Minds (#id15)One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve thereadability of code and make it consistent across the wide spectrum of Python code. As PEP 20 (/dev/peps/pep-0020) says, "Readability counts".

Navigation menu