Summary of python naming variable rules

Summary of python naming variable rules

1. Capital letters and underscore capital letters
are used to represent constants, for example: CONST_VALUE = 0

2. Camel case
is used to represent classes, for example: MyClass

3. Lowercase letters are underlined. Lowercase letters
are used to represent modules, variables, function names, and method names, for example: numpy

4. Underscore
1. Single underscore: used as a loop variable, no longer used, only as a placeholder
2. Pre-single underscore: weak private, agreeing that the properties and methods beginning with a single underscore are used internally by the class, and can still be used by <object name>.<property name>, from xx import * will not import methods and properties starting with a single underscore.
3. Preceding double underscores: strong private, not inherited by subclasses. Attributes and methods starting with double underscores, for example: "__X" will be renamed by the interpreter as: "_<class name>__X".
4. Double underscores before and after: general naming has no effect, and some are used to reserve attributes or methods. Examples of this are, __init__ object constructor, __call__ makes an object callable. Do not misuse the names with double underscores before and after to avoid bugs.

Guess you like

Origin blog.csdn.net/a_13572035650/article/details/128434261