Questions tagged [pep8]

Coding conventions and style guidelines for Python. Not to be confused with the PEP/8 assembly language.

PEP (Python Enhancement Proposals) 8 describes coding conventions for code in the standard Python library. This PEP covers how code should be commented, use tabs or spaces to indent code, naming convention, the use of non-semantic white space, etc.

Many large projects have adopted PEP8 (at least in part) as part of their style guides.

The tool pep8 will report code-conformance to the PEP8 guidelines.

Questions tagged as pep8 should relate to how to apply these guidelines to your code.

The full text of PEP8 can be found at python.org.

829 questions
-3
votes
5 answers

Logic behind why python variables should be lowercase in functions but outside functions not necessarily

Is there any logic why it is acceptable to have variables with capital letters (e.g. myName = "Jason") inside if __name__ == "__main__": but not inside def main():? EDIT : as apparently there is confusion, I got this conclusion by activating PEP 8…
-3
votes
1 answer

How do you usually handle long-line code newline breaking in Python?

I have a long code looks like this: def to_representation(self, instance): res = super().to_representation(instance) res['receiver_phone_num'] = get_encryption_phone_num(instance.receiver_phone_num) if instance.receiver_phone_num else None …
Gorgine
  • 310
  • 2
  • 11
-3
votes
1 answer

Style: Ending code blocks with `pass` vs `return`/`continue` vs nothing

The pass statement in python does nothing except fill space. However, I've found it useful for designating the end of a long, complicated block of code, before the program continues: ... if condition is True: ... pass ... essentially, the…
Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
-5
votes
1 answer

What is the most efficient and well presented version of this code?

I'm trying to make a class which creates empty board objects as part of a board game project. Here's what I came up with : class Board: board = [] # Initially the board is empty def __init__(self, size=9): # If n is the size of…
1 2 3
55
56