🐍 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:
    pass

Functions, Methods & Variables

snake_case

def my_function_name():
    pass
 
my_variable_name = 0

Constants

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):
        pass

Files & Modules

snake_case

my_file_name.py
user_profile_manager.py

Packages (folders containing init.py)

Also snake_case

my_python_package/