Why Good Names Matter
Clear and consistent naming helps make code more readable, maintainable, and easier to debug.
General Guidelines
- Be descriptive: Names should clearly describe the variable, function, or class purpose.
- Use lowercase_with_underscores for variable and function names (snake_case).
- Use CapitalizedWords (PascalCase) for class names.
- Avoid abbreviations: unless they are widely known (e.g.,
id
, url
).
- Use singular nouns for variables representing single items and plural nouns for collections.
- Constants should be all uppercase with underscores (e.g.,
MAX_VALUE
).
Examples
# Variable names
user_name = "John"
total_price = 100.50
is_valid = True
# Function names
def calculate_total(price, tax):
return price + tax
# Class names
class ShoppingCart:
pass
# Constants
MAX_ITEMS = 100
Additional Tips
- Don't use names that conflict with Python built-in functions or keywords (e.g., avoid
list
, str
, id
as variable names).
- Use meaningful names even if longer is necessary—clarity beats brevity.
- Use verbs for function names (
get_data
, send_email
).
- Use nouns for variables and class names.
- Keep consistent style throughout the project.