1. Module
- The module uses lowercase names as much as possible, keeping the first letter lowercase and trying not to underline (unless there are multiple words and a small number of cases)
# 正确的模块名import decoderimport html_parser# 不推荐的模块名import Decoder
2. Class name
- The class name uses the Hump (CamelCase) naming style, capitalized, and the private class can start with an underscore
class Farm(): passclass AnimalFarm(Farm): passclass _PrivateFarm(Farm): pass
- Place related classes and top-level functions in the same module. Unlike Java, there is no need to restrict a module to a class.
3. Functions
- Function names are lowercase, if there are multiple words, separated by underscores
def run(): passdef run_with_env(): pass
- The private function adds an underscore before the function _
class Person(): def _private_func(): pass
4. Variable name
- Variable names are as lowercase as possible, with multiple words, separated by underscores
if __name__ == ‘__main__‘: count = 0 school_name = ‘‘
- Constants are all uppercase, if there are multiple words, separated by underscores
MAX_CLIENT = 100MAX_CONNECTION = 1000CONNECTION_TIMEOUT = 600
5. Constants
- Constants are named with an underscore-delimited capitalization
Max_overflow= -Class FooBar: def foo_bar( Self , print_): print ( Print_)
Python code specification and naming conventions