How to zero the basis for learning python? Python code specification of naming

table of Contents

1, the module

  • Try to use lowercase module names, initials remain lowercase, try not to use the underscore (unless more than one word, and a small number of cases)
1  '' ' 
2  What I do not know how you can add in the learning process
 3  Python learning exchanges buttoned Qun, 934 109 170
 4  group, there are good tutorials, development tools and e-books.
5  Share python current business needs and your talent and how good python learning from zero base, and learn what content.
6  '' ' 
7  # correct module name 
. 8  Import Decoder
 . 9  Import html_parser
 10   
. 11  # is not recommended name of the module 
12 is  Import Decoder

 

2, the class name

  • Class names use camel (CamelCase) naming style, capitalized, beginning underscore a private class available
1 class Farm():
2     pass
3 
4 class AnimalFarm(Farm):
5     pass
6 
7 class _PrivateFarm(Farm):
8     pass

 

  • The related classes and top-level functions in the same module. Unlike Java, a class is not necessary to limit a module.

3, function

  • Function name all lower case, if multiple words separated by underscores
1 def run():
2     pass
3 
4 def run_with_env():
5     pass

 

  • Private function before the function adds an underscore _
1 class Person():
2 
3     def _private_func():
4         pass

 

4, the variable name

  • Try to lowercase variable names, if multiple words separated by underscores
1 if __name__ == '__main__':
2     count = 0
3     school_name = ''

 

  • Constant all-uppercase, separated if multiple words, use underscores
1 MAX_CLIENT = 100
2 MAX_CONNECTION = 1000
3 CONNECTION_TIMEOUT = 600

 

5, Constant

  • Constant use uppercase names separated by an underscore
1 MAX_OVERFLOW = 100
2 
3 Class FooBar:
4 
5     def foo_bar(self, print_):
6         print(print_)

 

Guess you like

Origin www.cnblogs.com/xiaoyiq/p/11403529.html