-
Basic principles : Python language identifier must begin with a letter, underscore _ can not begin with a number, it can be followed by any number of letters, numbers and underscore _. Letters here is not limited to the 26 English letters, may contain Chinese characters, Japanese characters and so on.
-
Taboo : Python also contains a list of keywords and built-in functions, you can not use them as variable names to prevent conflict.
Common naming rules:
Project name: the first letter capitalized and the rest lowercase word, multi-word combinations are underlined division. Hump material may also be used.
Package name, module name: all-lowercase
class name: the first letter capitalized other letters lowercase, and more use of the word hump body
method: lowercase words
function: If the parameter name and function of reserved keywords conflict, then add an underscore in the parameter , much better than the alphabet, such as reptiles class_ = "info".
Global variables: all-uppercase, with underscores multi-word segmentation -
Note :
- Whether or class member variables are global variables, or g m not use the prefix.
- Private class members to use a single underscore prefix to identify, define and more public members, less-defined private members.
- The variable name with the type of information should not be, because Python is dynamically typed language. As iValue, names_list, dict_obj, etc. are bad name.
- Beginning, the end, usually python own variables, not named in this way
- Beginning with a double underscore __, it is a private instance variable (not direct external access), named in accordance with the situation
Python language naming what?
Guess you like
Origin blog.csdn.net/YJG7D314/article/details/104003165
Recommended
Ranking