Skip to content

What is the naming convention in Python for variable and function?

In Python, variable and function names should be lowercase, with words separated by underscores. For example:

Naming convention in Python

python
my_variable = "Hello, world!"

def my_function():
    print("This is my function.")

<div class="alert alert-info flex not-prose"> Watch a course Python - The Practical Guide</div>

Additionally, variable and function names should be descriptive and meaningful, in order to make the code more readable and easier to understand.

Dual-run preview — compare with live Symfony routes.