Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 10 of 10 · Python Basics & Syntax
Interview question

What is PEP 8 and why does it matter? PEP 8 क्या है और यह क्यों important है?

Answer

PEP 8 is Python's official style guide, defining conventions for naming, indentation, line length, imports, and formatting to keep code consistent and readable across projects and teams.

RuleConvention
Indentation4 spaces, no tabs
Line lengthMax 79 characters (some teams use 88-120)
Variable/function namessnake_case
Class namesPascalCase (CapWords)
ConstantsUPPER_SNAKE_CASE
# PEP 8 compliant
MAX_RETRIES = 5

class UserAccount:
    def __init__(self, user_name):
        self.user_name = user_name

    def get_display_name(self):
        return self.user_name.title()

# Not PEP 8 compliant
class useraccount:
    def __init__(self,UserName):
        self.UserName=UserName

Tools like flake8, pylint, and black help automatically check or enforce PEP 8 compliance.

PEP 8 Python की official style guide है, naming, indentation, line length, imports, formatting के conventions define करती है ताकि code consistent और readable रहे।

RuleConvention
Indentation4 spaces, tabs नहीं
Line lengthMax 79 characters
Variable/function namessnake_case
Class namesPascalCase
MAX_RETRIES = 5

class UserAccount:
    def __init__(self, user_name):
        self.user_name = user_name

    def get_display_name(self):
        return self.user_name.title()

flake8, pylint, black जैसे tools PEP 8 compliance check/enforce करने में मदद करते हैं।

Was this answer clear?