Variable Naming Conventions

Carson West

Variables and Data Types

Variable Naming Conventions

Python’s variable naming follows specific conventions for readability and maintainability. Inconsistent naming can lead to errors and make code harder to understand.

Key Principles:

Examples:

# Good examples
user_name = "Alice"
product_price = 99.99
is_active = True
MAX_ATTEMPTS = 3

# Bad examples
usrnm = "Bob"       # Too short and cryptic
productPrice = 10  # Inconsistent casing
2items = 2        # Starts with a number (invalid)
if = 1             # Uses a reserved keyword (invalid)

Further Notes:

Example of referencing another note:

For a more in-depth explanation on how to choose effective variable names, refer to Choosing Descriptive Variable Names.