1. Module
- Modules should be named in lowercase as much as possible, the first letter should be kept lowercase, and try not to use underscores (unless there are multiple words and a small number of them)
# 正确的模块名
import decoder import html_parser # 不推荐的模块名 import Decoder
2. Class name
- Class names use CamelCase naming style, the first letter is capitalized, and 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 a class to a module.
3. Function
- Function names are always in lowercase, and 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 as much as possible, and if there are multiple words, separate them with underscores
if __name__ == '__main__': count = 0 school_name = ''
- Constants are in all uppercase, and if there are multiple words, separate them with underscores
MAX_CLIENT = 100 MAX_CONNECTION = 1000 CONNECTION_TIMEOUT = 600
5. Constants
- Constants are named in uppercase separated by underscores
MAX_OVERFLOW = 100 Class FooBar: def foo_bar(self, print_): print(print_)