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.
| Rule | Convention |
|---|---|
| Indentation | 4 spaces, no tabs |
| Line length | Max 79 characters (some teams use 88-120) |
| Variable/function names | snake_case |
| Class names | PascalCase (CapWords) |
| Constants | UPPER_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=UserNameTools 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 रहे।
| Rule | Convention |
|---|---|
| Indentation | 4 spaces, tabs नहीं |
| Line length | Max 79 characters |
| Variable/function names | snake_case |
| Class names | PascalCase |
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?