I,Package name, Module name, local variable name, function name
All lower case + underlined hump
Example: this_is_var
2. Global Variables
Full upper case + underlined hump
Example: GLOBAL_VAR
Iii. Class Name
Upper-case hump
Example: ClassName ()
4. Underline
Example for 1:
The variables var_1, _ var_2, _ var_3 are defined in the module_1 module.
The code in the module_2 module is as follows:
module_1 * _var_2
An error will be reported when you execute lines 6 and 7, because they will not be imported.
Since it is a weak internal identifier, there is still a way to use it, just import it separately:
module_1 * module_1 _var_2, _var_2
Example for 2:
self.var_1 = 1 self._var_2 = 2 self. = 3 == obj = obj.
= 1= 2 = 3 self. === obj.get_var_3()
4. Other notes
- Do not use start letters to identify the variable type (such as iValue) Like in c, because python determines the type only when interpreting it.
- Because exceptions are also a class, they follow the class naming rules. In addition, if an exception actually refers to an Error, Use "Error" as the suffix.
- Try to use full spelling words for naming. There are two abbreviations: Common abbreviations, such as XML and ID. Only the first letter, such as XmlParser, should be capitalized. The name contains long words, which are abbreviated to a word. In this case, we should use the abbreviated form of conventions. For example, function stands for fn, text stands for txt, object stands for obj, count stands for cnt, and number stands for num.
- The first parameter of the class instance method uses self, and the first parameter of the class method uses cls
5. Finally, some English instructions are used as remarks.
Since module names are mapped to file names, and some file systems are