Python language naming what?

  1. 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.

  2. 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

  3. Note :

    1. Whether or class member variables are global variables, or g m not use the prefix.
    2. Private class members to use a single underscore prefix to identify, define and more public members, less-defined private members.
    3. 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.
    4. Beginning, the end, usually python own variables, not named in this way
    5. Beginning with a double underscore __, it is a private instance variable (not direct external access), named in accordance with the situation
Published 478 original articles · won praise 673 · views 190 000 +

Guess you like

Origin blog.csdn.net/YJG7D314/article/details/104003165