Python crawler face questions 170: 2019 Edition [2]

Coding Standards

11. Do you know exemplified Python naming objects, methods, or the like e.g.

 

File name 
all lowercase, you can use the underscore 
package 
should be short, lowercase names. If underscore can be added to improve readability. As mypackage. 
Module 
specifications and the same package. As mymodule. 
Class 
always use the first letter capitalized word string. Such as MyClass. You can use an extra inner class leading underscore. 
Functions & Methods 
Function names should be lowercase, you can use the underline style word to increase readability. Such as: myfunction, my_example_function. 
* * Note : mixed case is allowed only for time already take advantage of this style, in order to maintain backward compatibility. 
Function parameters and methods 
always use "self" as an example of the method of the first parameter. Always use "cls" class method as the first parameter. 
If the parameter name of a function and retention of key conflict, usually a good underscore suffix to use abbreviations or strange spelling. 
Global variables 
for M Import from * import statements, if you want to stop global variable import module can use the old standard, on a global variable plus a leading underscore.
* * Note : Avoid using global variables 
variable 
variable name all lowercase, connected by underlining each word. The Color = the WHITE, this_is_a_variable = . 1 
* * Note :
1 . Whether class member variable or a global variable is not used by the prefix m or g.
2 . Private class members to use a single underscore prefix to identify, define and more public members, less-defined private members.
3 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. 
Constant 
constant name in all capital letters, each connected by underlining words such as MAX_OVERFLOW, TOTAL. 
Abnormal 
to "Error" as a suffix. 
Abbreviations 
situation should try to use the full name word spelling, abbreviations of the following two ways: 
1 . Commonly used abbreviations, such as XML, ID, etc., when naming should be only the first letter capitalized, such as XmlParser.
2 . Name contains long words on a word abbreviations. At this convention ChengSu abbreviations should be used. 
For example: 
function abbreviated as the Fn 
text abbreviated as TXT 
Object abbreviated obj 
COUNT abbreviated cnt 
Number The abbreviated num, and so on. 
Leading underscore suffix 
a leading underscore: that non-public. 
A suffix underlined: avoid keyword conflicts. 
Two leading underscores: Used when naming a class attribute name cause conflict.
Two leading and trailing underscore: "Magic" (Fig special) or an object property, e.g. __init__ or __file__. Never create such a name, but only to use them.

 

There are several comments in 12.Python?

As a comment line with the # 
# as a comment here 
generally use "" " (three quotes) can comment multiple lines, but generally used to indicate the function documentation 
" "" 
Here is a comment 
function to function. . . . 
"" "

13. How elegant function to add a comment?

1 When you write code for yourself: 
comments as outline code of 
living has become superfluous to delete any comment 
using annotations to define your own code the tricky part 
2 when writing code for others: 
complex method name is not easy to understand if there is or function, you need to add a brief comment after the def line to illustrate the problem 
for any public function, try to contain an associated docstring 
avoid: WET comment 
avoid: use notes to make up the code 
to avoid: rude comments.

14. How to add a comment to the variable?

docstring

15.Python code indentation in whether to support the Tab key and spaces mix.

python syntax is not supported by the code indentation with TAB and spaces mix

16. Can you import multiple libraries in an import in?

Although you can use the import statement to import one or any number of standard library extension library, but it is recommended that a time or import a standard library extensions

17. What should be noted in the file name to Py time?

Note that the same name,
All lowercase, you can use an underscore

18. The specifications include several tools Python style

Pylint,black

19. The list of basic data types in Python?

int,bool,str,list,tuple,dict,set

20. How to distinguish the variable data types and data types immutable

Variable Data type: in the case of the same id, value can be changed (and dictionaries are list variable type, but the key value in the dictionary must be immutable type) 
immutable data types: value change, id change too. (Number, string, boolean, not all types)

 

Guess you like

Origin www.cnblogs.com/reseelei-despair/p/11317099.html