π Naming Conventions
Good to know
β Python follows the official PEP 8 style guide.
β Naming is part of writing clean, readable Python β especially in larger projects.
Classes
PascalCase (a.k.a. CapWords)
class MyClassName:
passFunctions, Methods & Variables
snake_case
def my_function_name():
pass
my_variable_name = 0Constants
UPPERCASE_WITH_UNDERSCORES
(Usually defined at the top of a module)
MAX_RETRY_COUNT = 5
API_BASE_URL = "https://example.com"Private Variables & Methods
Prefix with _single_leading_underscore
Signals: βinternal use onlyβ
class User:
def __init__(self):
self._password = "secret" # pseudo-private
self.__token = "xyz" # name-mangled (User._User__token)
def _internal_method(self):
passFiles & Modules
snake_case
my_file_name.py
user_profile_manager.pyPackages (folders containing init.py)
Also snake_case
my_python_package/