What is PEP 8?
PEP 8 is the official style guide for Python code. PEP stands for Python Enhancement Proposal. It was first written in 2001 and gives simple rules so that everyone writes Python in a similar, readable way.
- Use 4 spaces for each indentation level, not tabs.
- Keep lines up to 79 characters.
- Use
snake_casefor variables and functions, andCapWordsfor class names. - Put spaces around operators and after commas.
- Leave two blank lines between top-level functions and classes.
# Not PEP 8 style
def AddNumbers(a,b):
return a+b
x=AddNumbers(2,3)
# PEP 8 style
def add_numbers(a, b):
return a + b
total = add_numbers(2, 3)
Both versions work, but the second one is easier to read. Tools like flake8 and black can check or fix the style automatically.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |