| Category | Case | Example |
|---|---|---|
| Modules | snake_case | import my_module |
| Packages | snake_case | from my_package import ... |
| Variables | snake_case | my_variable = 10 |
| Constants | SCREAMING_SNAKE_CASE | MY_CONSTANT = 10 |
| Functions | snake_case | def my_function(): ... |
| Methods | snake_case | def my_method(self): ... |
| Classes | PascalCase | class MyClass: ... |
| Exceptions | PascalCase | class MyException(Exception): ... |
| Properties | snake_case | @property def my_property(self): ... |
| Global Variables | snake_case | global my_global |
| Private Variables | _snake_case | _my_variable = 10 |
| Private Methods | _snake_case | def _my_method(self): ... |
my_id instead of my_ID.MY_ID.HTTPServerError rather than HttpServerError.version1 (snake case) or VERSION1 (screaming snake case).version_1 (for snake case) and Version1 (for pascal case).When using type variables in Python (introduced in PEP 484), it's recommended to use CapWords for type variable names. Common examples include short names like T, AnyStr, or Num.
Additionally, when declaring covariant or contravariant behavior in type variables, you can use the suffixes _co for covariant types and _contra for contravariant types. Here's an example:
from typing import TypeVar
VT_co = TypeVar('VT_co', covariant=True)
KT_contra = TypeVar('KT_contra', contravariant=True)