W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
你可以使用反斜線來繼續(xù)一個(gè)語句,在這種情況下,你應(yīng)該對(duì)齊下一行到最后一個(gè) 點(diǎn)或等號(hào)或縮進(jìn)四個(gè)空格:
this_is_a_very_long(function_call, 'with many parameters') \
.that_returns_an_object_with_an_attribute
MyModel.query.filter(MyModel.scalar > 120) \
.order_by(MyModel.name.desc()) \
.limit(10)
如果在一個(gè)帶括號(hào)的語句中換行,對(duì)齊到括號(hào):
this_is_a_very_long(function_call, 'with many parameters',
23, 42, 'and even more')
對(duì)于有許多元素的元組或列表,在起始括號(hào)后立即換行:
items = [
'this is the first', 'set of items', 'with more items',
'to come in this line', 'like this'
]
頂層函數(shù)和類由兩個(gè)空行分隔,其它東西一行。不要使用太多的空行來分隔 代碼中的邏輯段。示例:
def hello(name):
print 'Hello %s!' % name
def goodbye(name):
print 'See you %s.' % name
class MyClass(object):
"""This is a simple docstring"""
def __init__(self, name):
self.name = name
def get_annoying_name(self):
return self.name.upper() + '!!!!111'
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: