
您总是可以在多条物理线之间加上括号来扩展逻辑线:
answer = ( 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel.")
这称为隐式线连接。
上面使用PEP8一切缩进一步的样式(称为悬挂缩进)。您也可以缩进多余的行以匹配左括号:
answer = ('Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel.")但这会使您更快地达到80列的最大值。
您将
if和放在哪个位置完全
else取决于您;我在上面使用了我的个人喜好,但是对于 *** 作员,尚没有任何人同意的特定样式。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)