Home >Backend Development >Python Tutorial >What is the Preferred Naming Convention for Python Variables and Functions?
In Python, you're likely to encounter two naming conventions for variables and functions, just as you did in C#: CamelCase and PascalCase. However, there's an additional convention you may encounter in Python, known as snake_case.
So, which of these conventions is the preferred style for Python?
The answer lies in the Python Enhancement Proposal 8 (PEP 8) style guide. According to PEP 8:
For function names:
For variable names:
Example:
# snake_case this_is_my_variable = 'a' def this_is_my_function():
Therefore, snake_case is the preferred and definitive coding style for variables and functions in Python, as outlined in the official PEP 8 guidelines.
The above is the detailed content of What is the Preferred Naming Convention for Python Variables and Functions?. For more information, please follow other related articles on the PHP Chinese website!