Naming conventions
Naming convention
1. Modules
Try to use lowercase names for modules, and keep the first letter in lowercase as much as possible. Do not use underscores (unless there are multiple words and a small number)
# 正确的模块名 import decoder import html_parser # 不推荐的模块名 import Decoder
2. Class name
The class name uses CamelCase naming style, the first Capital letters, private classes can start with an underscore
class Farm(): pass class AnimalFarm(Farm): pass class _PrivateFarm(Farm): pass
Put related classes and top-level functions in the same module. Unlike Java, there is no need to limit one class to one module.
3. Function
Function names must be lowercase. If there are multiple words, separate them with underscores
def run(): pass def run_with_env(): pass
For private functions, add an underscore before the function_
class Person(): def _private_func(): pass
4. Variable names
Variable names should be in lowercase letters. If there are multiple words, separate them with underscores.
if __name__ == '__main__': count = 0 school_name = ''
Constants should be in all uppercase letters. If there are multiple words, Use underscores to separate
MAX_CLIENT = 100 MAX_CONNECTION = 1000 CONNECTION_TIMEOUT = 600
5. Constants
Constant names are named in uppercase letters separated by underscores
MAX_OVERFLOW = 100 Class FooBar: def foo_bar(self, print_): print(print_)