Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e96ef2

Browse files
committed
midnight
1 parent 9e6fc83 commit 8e96ef2

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

‎README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,104 @@ long_variable = 3
291291
```
292292

293293
<h5 id="5.2">其他建议</h5>
294+
在任何地方避免使用尾随空格。
295+
296+
在二元运算符周围使用空格:
297+
298+
```python
299+
Yes:
300+
301+
i = i + 1
302+
submitted += 1
303+
x = x*2 - 1
304+
hypot2 = x*x + y*y
305+
c = (a+b) * (a-b)
306+
307+
No:
308+
309+
i=i+1
310+
submitted +=1
311+
x = x * 2 - 1
312+
hypot2 = x * x + y * y
313+
c = (a + b) * (a - b)
314+
```
315+
表示关键字参数货默认参数值时,不要使用空格:
316+
317+
```python
318+
Yes:
319+
320+
def complex(real, imag=0.0):
321+
return magic(r=real, i=imag)
322+
No:
323+
324+
def complex(real, imag = 0.0):
325+
return magic(r = real, i = imag)
326+
```
327+
函数注释的场景:
328+
329+
```python
330+
Yes:
331+
332+
def munge(input: AnyStr): ...
333+
def munge() -> AnyStr: ...
334+
335+
No:
336+
337+
def munge(input:AnyStr): ...
338+
def munge()->PosInt: ...
339+
```
340+
341+
当参数注释和默认值共存时:
342+
343+
```python
344+
Yes:
345+
346+
def munge(sep: AnyStr = None): ...
347+
def munge(input: AnyStr, sep: AnyStr = None, limit=1000): ...
348+
349+
No:
350+
351+
def munge(input: AnyStr=None): ...
352+
def munge(input: AnyStr, limit = 1000): ...
353+
```
354+
355+
复合声明不建议使用:
356+
357+
```python
358+
Yes:
359+
360+
if foo == 'blah':
361+
do_blah_thing()
362+
do_one()
363+
do_two()
364+
do_three()
365+
366+
Rather not:
367+
368+
if foo == 'blah': do_blah_thing()
369+
do_one(); do_two(); do_three()
370+
```
371+
372+
下面这种丑就不多说了:
373+
374+
```python
375+
Rather not:
376+
377+
if foo == 'blah': do_blah_thing()
378+
for x in lst: total += x
379+
while t < 10: t = delay()
380+
381+
Definitely not:
382+
383+
if foo == 'blah': do_blah_thing()
384+
else: do_non_blah_thing()
385+
386+
try: something()
387+
finally: cleanup()
388+
389+
do_one(); do_two(); do_three(long, argument,
390+
list, like, this)
391+
392+
if foo == 'blah': one(); two(); three()
393+
```
294394

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /