代码注释没必要翻译、翻译用点心。。brace/bracket/parenthes是三种括号,不是都翻译成括号 不会的百度,
娃哈哈店长
4年前
修改理由:
此投稿已在 4年前 合并。
内容修改:
Old | New | Differences |
---|---|---|
1 | ## | |
1 | ## 代码布局 | |
2 | 2 | |
3 | ### | |
3 | ### 缩进 | |
4 | 4 | |
5 | 每个 | |
5 | 每个缩进使用四个空格 | |
6 | 6 | |
7 | 延续线应使用 | |
7 | 延续线应使用 Python 的隐式线在括号,括号和花括号内垂直对齐,或使用_hanging indent _ 对齐的元素。使用悬挂式压痕时,应考虑以下事项;在第一行上不应有任何争论,并应使用进一步的缩进以清楚地区分自己作为延续行。 | |
8 | 8 | |
9 | ||
9 | 正确: | |
10 | 10 | |
11 | 11 | ``` |
12 | # Aligned with opening delimiter. | |
13 | foo = long_function_name(var_one, var_two, | |
14 | var_three, var_four) | |
12 | 15 | |
13 | #与打开的定界符对齐。 | |
16 | # Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest. | |
17 | def long_function_name( | |
18 | var_one, var_two, var_three, | |
19 | var_four): | |
20 | print(var_one) | |
14 | 21 | |
15 | foo = long_function_name(var_one,var_two, | |
22 | # Hanging indents should add a level. | |
23 | foo = long_function_name( | |
24 | var_one, var_two, | |
25 | var_three, var_four) | |
26 | ``` | |
16 | 27 | |
17 | var_three,var_four) | |
18 | ||
19 | #添加4个空格(一个额外的缩进级别)以区别于其余部分。 | |
20 | ||
21 | deflong_function_name( | |
22 | ||
23 | var_one,var_two,var_three, | |
24 | ||
25 | var_four): | |
26 | ||
27 | print(var_one) | |
28 | ||
29 | #悬挂缩进应添加一个级别。 | |
30 | ||
31 | foo = long_function_name( | |
32 | ||
33 | var_one,var_two, | |
34 | ||
35 | var_three,var_four) | |
28 | 错误: | |
36 | 29 | |
37 | 30 | ``` |
31 | # Arguments on first line forbidden when not using vertical alignment. | |
32 | foo = long_function_name(var_one, var_two, | |
33 | var_three, var_four) | |
38 | 34 | |
39 | 没有: | |
40 | ||
35 | # Further indentation required as indentation is not distinguishable. | |
36 | def long_function_name( | |
37 | var_one, var_two, var_three, | |
38 | var_four): | |
39 | print(var_one) | |
41 | 40 | ``` |
42 | 41 | |
43 | #不使用垂直对齐时禁止在第一行中使用参数。 | |
44 | ||
45 | foo = long_function_name(var_one,var_two, | |
46 | ||
47 | var_three,var_four) | |
48 | ||
49 | #由于缩进是不可区分的,因此需要进一步缩进。 | |
50 | ||
51 | deflong_function_name( | |
52 | ||
53 | var_one,var_two,var_three, | |
54 | ||
55 | var_four): | |
56 | ||
57 | print(var_one) | |
58 | ||
59 | ``` | |
60 | ||
61 | 对于连续线,4空格规则是可选的。 | |
42 | 对于连续线,4 空格规则是可选的。 | |
62 | 43 | |
63 | 44 | 可选的: |
64 | 45 | |
65 | 46 | ``` |
66 | #悬挂缩进*可能*缩进到4个以上的其他空格。 | |
47 | # Hanging indents *may* be indented to other than 4 spaces. | |
48 | foo = long_function_name( | |
49 | var_one, var_two, | |
50 | var_three, var_four) | |
51 | ``` | |
67 | 52 | |
68 | foo = long_function_name( | |
69 | ||
70 | var_one,var_two, | |
71 | ||
72 | var_three,var_four) | |
53 | 如果 if 语句的条件部分足够长,需要跨多行编写,则值得注意的是,两个字符关键字(即 if )的组合是一个自然的空格,加上一个空格。多行有条件的后续行的4空格缩进。这可能会产生与在if语句中嵌套的缩进代码套件的视觉冲突,这自然也会缩进 4 个空间。此PEP在如何(或是否)从 if 语句内的嵌套套件进一步视觉上区分此类条件线方面没有明确的位置。在此情况下可接受的选项包括但不限于: | |
73 | 54 | |
74 | 55 | ``` |
56 | # No extra indentation. | |
57 | if (this_is_one_thing and | |
58 | that_is_another_thing): | |
59 | do_something() | |
75 | 60 | |
76 | 如果if语句的条件部分足够长,需要跨多行编写,则值得注意的是,两个字符关键字(即if)的组合是一个自然的空格,加上一个空格。多行有条件的后续行的4空格缩进。这可能会产生与在if语句中嵌套的缩进代码套件的视觉冲突,这自然也会缩进4个空间。此PEP在如何(或是否)从if语句内的嵌套套件进一步视觉上区分此类条件线方面没有明确的位置。在此情况下可接受的选项包括但不限于: | |
61 | # Add a comment, which will provide some distinction in editors | |
62 | # supporting syntax highlighting. | |
63 | if (this_is_one_thing and | |
64 | that_is_another_thing): | |
65 | # Since both conditions are true, we can frobnicate. | |
66 | do_something() | |
77 | 67 | |
78 | ||
79 | ``` | |
80 | #没有额外的缩进。 | |
81 | ||
82 | if (this_is_one_thing and | |
83 | ||
84 | that_is_another_thing): | |
85 | ||
86 | do_something() | |
87 | ||
88 | #添加一条注释,它将在编辑器中提供一些区别 | |
89 | ||
90 | #支持语法突出显示。 | |
91 | ||
92 | if (this_is_one_thing and | |
93 | ||
94 | that_is_another_thing): | |
95 | ||
96 | #由于两个条件均为真,因此我们可以进行梳理。 | |
97 | ||
98 | do_something() | |
99 | ||
100 | #在条件延续行上添加一些额外的缩进。 | |
101 | ||
102 | if (this_is_one_thing | |
103 | ||
104 | and that_is_another_thing): | |
105 | ||
106 | do_something() | |
68 | # Add some extra indentation on the conditional continuation line. | |
69 | if (this_is_one_thing | |
70 | and that_is_another_thing): | |
71 | do_something() | |
107 | 72 | ``` |
108 | 73 | |
109 | 74 | |
110 | 75 | (另请参阅下面关于在二进制运算符之前或之后中断的讨论。) |
111 | 76 | |
112 | 多行构造的右 | |
77 | 多行构造的右大括号/方括号/括弧可以是列表中最后一行的第一个非空白字符下的一行,如下所示: | |
113 | 78 | |
114 | 79 | ``` |
115 | ||
116 | my_list == [ | |
117 | ||
118 | 1、2、3, | |
119 | ||
120 | 4、5、6, | |
121 | ||
122 | ] | |
123 | ||
124 | result= some_function_that_takes_arguments( | |
125 | ||
126 | 'a','b','c', | |
127 | ||
128 | 'd','e','f', | |
129 | ||
130 | ) | |
131 | ||
80 | my_list = [ | |
81 | 1, 2, 3, | |
82 | 4, 5, 6, | |
83 | ] | |
84 | result = some_function_that_takes_arguments( | |
85 | 'a', 'b', 'c', | |
86 | 'd', 'e', 'f', | |
87 | ) | |
132 | 88 | ``` |
133 | 89 | |
134 | 90 | 或者可以在开始多线构造的线的第一个字符下进行排列,如下所示: |
135 | 91 | |
136 | 92 | ``` |
137 | ||
138 | my_list == [ | |
139 | ||
140 | 1、2、3, | |
141 | ||
142 | 4、5、6, | |
143 | ||
93 | my_list = [ | |
94 | 1, 2, 3, | |
95 | 4, 5, 6, | |
144 | 96 | ] |
145 | ||
146 | result= some_function_that_takes_arguments( | |
147 | ||
148 | 'a','b','c', | |
149 | ||
150 | 'd','e','f', | |
151 | ||
97 | result = some_function_that_takes_arguments( | |
98 | 'a', 'b', 'c', | |
99 | 'd', 'e', 'f', | |
152 | 100 | ) |
153 | ||
154 | 101 | ``` |