Python syntax Features: Notes / write rules / naming

1. Comment

    1) single-line comment #

    Front 2) three single multi-line comments or double quotes '' '...' '' "" "..." ""

    3) Chinese encoding declaration comment

          # - * - coding: encoding - * -

         Encoding or # coding =

               The use of a UTF-8 encoding, is set as urf-8; GBK coding if used, or the use gbk cp936

 

2. The code indentation

    Use a colon to distinguish between code level.

    Four spaces or as a Tab key to indent. It recommended four spaces.

   You can set shortcuts in the IDE, indent or anti-indent.

 

3. Encoding Rules

   As the coding specifications PEP8

   1) Each import only introduced a module, to avoid introducing a plurality of modules.

   2) Do not add titles at the end of each line; do not use the title two commands put together.

    3) Each line is not more than 80 characters. If it exceeds the small brackets () displayed to branch. Not recommended backslash

    4) the necessary blank line. Space between the top two lines of the definition, a blank line between method definitions.

    Both 5) operator function parameters between, separated by spaces recommendations

     6) Avoid using accumulation loop ++ = string. Strings are immutable, doing so would create unnecessary temporary objects. Each string added to the list, a connection list join ()

     7) The appropriate procedure to use structured exception handling to improve fault tolerance, but not much depend on exception handling structure, appropriate display determination is necessary.

 

4. naming

    1) the name of the module short as possible and use all lowercase letters, you can use an underscore.

    2) Try to short package name, and use all lowercase letters, not recommended underlined.

    3) classes with the first letter in upper case

    4) inside the module class with an underscore + Pascal style

    5) the properties and methods of naming rules, class with similar modules. Lower case letters are used, a plurality of divided underlined letters

    6) use all capital letters when common name, you can use an underscore

    7) Use of a single underline the beginning of the variable or function module is protected in use from module import * statement from xxx import, these variable or function can not be introduced

    Instance variables or method 8) at the beginning of double-underlined private class

 

Guess you like

Origin www.cnblogs.com/lelin/p/11229266.html