---
title: "What is meant by PEP 8 style guide?Give suitable example."  
description: "What is meant by PEP 8 style guide?Give suitable example."  
author: "Amrita Bhattacharjee"  
published: 2023-03-28  
updated: 2023-04-03  
canonical: https://www.mindstick.com/forum/157640/what-is-meant-by-pep-8-style-guide-give-suitable-example  
category: "python"  
tags: ["python"]  
reading_time: 3 minutes  

---

# What is meant by PEP 8 style guide?Give suitable example.

What is meant by PEP 8 [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) [guide](https://www.mindstick.com/articles/44463/business-to-business-vat-reclaiming-a-guide-for-your-employees)?Give suitable example.

## Replies

### Reply by Krishnapriya Rajeev

PEP, or *Python Enhancement Proposal*, refers to several documents that describe new features that are proposed for Python and document aspects of Python, such as design and style. These documents are released to the developer community.

PEP 8 (also called PEP8 or PEP-8) is a PEP document that provides guidelines and the best practices for writing Python code. Written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan, the main focus of PEP 8 is to improve the readability and consistency of Python code.

A few of the *key guidelines* to be followed according to PEP 8 are:

1. **Naming Conventions**

Choosing sensible names that will save you time and energy later. For example, avoiding single-letter names like l and O is more efficient, as these can look similar to 1 and 0 which may confuse.

2. **Naming Styles**

- Functions: Use the lowercase word(s) separated by underscores. Example: my_function()
- b. Variables: Use lowercase single letters or word(s) separated by underscores. Examples: x, my_variable
- Class: Use camel case for all class names with no space between words. Example: MyClass
- Constants: Use uppercase single letter or word(s) separated by underscores. Examples: CONSTANT, MY_CONSTANT
- Packages: Use the short lowercase word(s). Do not separate the words with underscores. Example: mypackage

3. **Code Layout**

a. *Using blank lines*:

Surround top-level functions and classes with two blank lines.

```plaintext
class MyClass1:
pass

class MyClass2:
pass

def top_level_function():
return 1
Surround method definitions inside classes with a single blank line.
class MyClass:
def method_one(self):
 return 1
def method_two(self):
 return 2
```

Use blank lines sparingly within the functions to show clear steps. This can be done at the programmer's discretion

b. *Maximum Line Length*:

PEP 8 suggests lines be limited to 79 characters in length to allow users to have multiple files open next to one another while avoiding line wrapping.

c. *Indentation*:

The key indentation rules laid out in PEP 8 are the following:\
Use 4 consecutive spaces to indicate indentation.\
Prefer spaces over tabs.

d. *Lining up the Closing Brace*:

- PEP 8 provides two options for the position of the closing brace:\ Line up the closing brace with the first non-whitespace character of the previous line.

```plaintext
list = [
		1, 2, 3,
		4, 5, 6,
		7, 8, 9
		]
```

- Line up the closing brace with the first character of the line that starts the construct.

```plaintext
list = [
		1, 2, 3,
		4, 5, 6,
		7, 8, 9
]
```

e. *Comments*:

One should limit the line length of comments and docstrings to 72 characters. Make sure to use complete sentences, starting with a capital letter. Do not forget to update comments if you change your code.


---

Original Source: https://www.mindstick.com/forum/157640/what-is-meant-by-pep-8-style-guide-give-suitable-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
