Home > Article > Backend Development > What are the naming rules of python language?
Python language naming rules:
1. Module:
Try to use lowercase names for modules, with the first letter Keep it lowercase and try not to use underscores (unless there are multiple words and a small number).
# 正确的模块名import decoderimport html_parser # 不推荐的模块名import Decoder
2. Class name:
The class name uses CamelCase naming style, with the first letter capitalized. Private classes can start with an underscore.
class Farm(): pass class AnimalFarm(Farm): pass class _PrivateFarm(Farm): pass
3. Function:
Function names must be lowercase. If there are multiple words, separate them with underscores.
def run(): pass def run_with_env(): pass
Private functions add an underscore_ before the function.
class Person(): def _private_func(): pass
4. Variable name:
Variable names should be in lowercase letters. If there are multiple words, separate them with underscores.
if __name__ == '__main__': count = 0 school_name = ''
5. Constants:
Constants are named in uppercase letters separated by underscores.
MAX_OVERFLOW = 100 Class FooBar: def foo_bar(self, print_): print(print_)
It is recommended not to use == for Boolean comparisons.
# Yes if greeting:: pass # Noif greeting == True pass if greeting is True: # Worse pass
Recommended tutorial: "python tutorial"
The above is the detailed content of What are the naming rules of python language?. For more information, please follow other related articles on the PHP Chinese website!