Python commonly used PEP8 coding specification and recommended experience sharing

indentation

Each level is indented with 4 spaces.

Use vertical implicit indentation in parentheses or use hanging indentation.

EXAMPLE:
# (vertical implicit indentation) aligns the left parenthesis
Foo = long_funcTIon_name(var_one, var_two,
Var_three, var_four)

# (hanging indentation) In general, only one layer of indentation
Foo = long_funcTIon_name(
Var_one, var_two,
Var_three, var_four)

# (hanging indent) But in the following situation, you need to add another layer of indentation, and distinguish it from the subsequent statement block.
Def long_funcTIon_name(
Var_one, var_two, var_three,
Var_four):
Print(var_one)

#右跟退回退
My_list = [
1, 2, 3,
4, 5, 6,
]
Result = some_funcTIon_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', ​​'f',
)

Error demonstration:
# When using vertical alignment, the first line cannot have parameters.
Foo = long_function_name(var_one, var_two,
Var_three, var_four)

The suspension indentation of the # parameter cannot be distinguished from the subsequent indentation of the code block.
Def long_function_name(
Var_one, var_two, var_three,
Var_four):
Print(var_one)

# 右角不退退退,不推荐
My_list = [
1, 2, 3,
4, 5, 6,
]

Result = some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', ​​'f',
)

Maximum line width

The maximum line width per line is no more than 79 characters

General continuation lines can use backslashes

Do not use backslashes in parentheses

EXAMPLE:
# Without brackets, using backslashes
With open('/path/to/some/file/you/want/to/read') as file_1, \
Open('/path/to/some/file/being/written', 'w') as file_2:
File_2.write(file_1.read())

# Continued in brackets, try to continue after the operator
Class Rectangle(Blob):

Def __init__(self, width, height,
Color='black', emphasis=None, highlight=0):
If (width == 0 and height == 0 and
Color == 'red' and emphasis == 'strong' or
Highlight > 100):
Raise ValueError("sorry, you lose")
If width == 0 and height == 0 and (color == 'red' or
Approval is None):
Raise ValueError("I don't think so -- values ​​are %s, %s" %
(width, height))

Blank line

Two lines of blank lines are used to split the definition of top-level functions and classes

A single blank line is used to split the method in the class definition

EXAMPLE:
The # class's method definition is split with a single empty line, and two lines of empty lines separate the definition of the top-level function and class.
Class A(object):
Def method1():
Pass

Def method2():
Pass

Def method3():
Pass

Module import

Each module imported should be in a separate line

The import order is as follows: (There is a blank line split between the import of each module type, and the order of the modules in each group is sorted in ascending order from top to bottom according to the first letter of the module)

Standard library related third-party libraries local libraries

EXAMPLE:
# Sort by module initials, recursive accordingly
Import active
Import adidas
Import create

Error example:
#一row Import multiple modules
Import sys, os, knife

# Do not import by initials
Import create
Import active
Import beyond

String

Single quotes and double quotes work the same, but they must be guaranteed to exist in pairs and not mixed.
(It is recommended that sentences use double quotes, words use single quotes, but not mandatory.)

EXAMPLE:
#单号号 and double quotes have the same effect
Name = 'JmilkFan'
Name = "Hey Guys!"

Spaces in expressions and statements Avoid spaces in parentheses

EXAMPLE:
Spam(ham[1], {eggs: 2})

Error example:
Spam( ham[ 1 ], { eggs: 2 } )

Avoid spaces before commas, colons, and semicolons

EXAMPLE:
If x == 4: print x, y; x, y = y, x

Error example:
If x == 4 : print x , y ; x , y = y , x

There must be no spaces before the left parenthesis of the function call

EXAMPLE:
Spam(1)
Dct['key'] = lst[index]

Error example:
Spam (1)
Dct ['key'] = lst [index]

Cannot add multiple spaces before and after an operator such as assignment

EXAMPLE:
x = 1
y = 2
Long_variable = 3

Error example:
x = 1
y = 2
Long_variable = 3

Place a space on both sides of the binary operator. The compound operator involving = ( += , -= , etc.)
Comparison operators ( == , < , > , != , <> , <= , >= , in , not in , is , is not )
Logical operators ( and , or , not )

EXAMPLE:
a = b
a or b

# Operators in parentheses do not require spaces
Name = get_name(age, sex=None, city=Beijing)

Comment

The comment block comment block is usually applied before the code and has the same indentation as the code. Each line begins with '# ', and there is a single space after #.

EXAMPLE:
# Have to define the param `args(List)`,
# Otherwise will be capture the CLI option when execute `python manage.py server`.
# oslo_config: (args if args is not None else sys.argv[1:])
CONF(args=[], default_config_files=[CONFIG_FILE])

Single line comment (you should avoid unnecessary comments)

EXAMPLE:
x = x + 1 # Compensate for border

Document string

Car Android Player

Fuction:

1.Built-in BT, phonebook and BT music; 2. WIFI Built-in, support WIFI hotspot; 3. Support phonelink function 4. USB Function 5. Multi-format audio and video decoding, support 1080P full-format 6. Support rear view camera input; 7. Supports Internet APP download, install, uninstall 8. Mirror and link with Andriod Phone and IOS Phone 9. Audio:MP3 MP2 AAC OGG FLAC APE WMA WAV RM AC3 10. Vidio:AVI 3GP/MP4 MOV MPG MKV WMV RMVB 11. OSD Language: INDONESIA Melayu Denask Deutsch English Spain Filipino FRANCE Italiano POLSKI ,PORTUGUES ROMANA Svenska TURKCE PYCCKNN KOREA JAPAN Nederlands Brazil and many more

car android player, car android radio, car android player 7 inch, car android system, car android auto unit

Jiangmen soundrace electronics and technology co.,ltd. , https://www.soundracegroup.com