snake case
In programming, snake case is a naming convention where you write compound names by joining words with underscores (_
) and using only lowercase letters.
Using underscores to separate words in an identifier improves readability. Python follows snake case for variable, function, and module names.
Example
Here’s an example of snake case in action:
first_name = "John"
light_speed = 299_792_458
def get_user_list():
"""Returns a list of users."""
...
def calculate_total():
"""Calculates the total amount."""
...
In these examples, underscores separate words, making the identifiers easier to read. Lowercase letters are another characteristic of the snake case naming convention.
Related Resources
Tutorial
How to Write Beautiful Python Code With PEP 8
Learn how to write high-quality, readable code by using the Python style guidelines laid out in PEP 8. Following these guidelines helps you make a great impression when sharing your work with potential employers and collaborators.
For additional information on related topics, take a look at the following resources:
- Variables in Python: Usage and Best Practices (Tutorial)
- Defining Your Own Python Function (Tutorial)
- Writing Beautiful Pythonic Code With PEP 8 (Course)
- How to Write Beautiful Python Code With PEP 8 (Quiz)
- Variables in Python (Course)
- Variables in Python: Usage and Best Practices (Quiz)
- Defining and Calling Python Functions (Course)
- Defining Your Own Python Function (Quiz)