合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
括号内换行 ----------- Python 支持括号内的换行。这时有两种情况: 1) 第二行缩进到括号的起始处 ~~~ foo = long_function_name(var_one, var_two, var_three, var_four) ~~~ 2) 第二行缩进 4 个空格,适用于起始括号就换行的情形 ~~~ def long_function_name( var_one, var_two, var_three, var_four): print(var_one) ~~~ 反斜杠`\`换行 -------------- 对于长字符串、长表达式可以使用反斜杠`\`换行 1) 二元运算符(如:`+` `.`等)应出现在行末 ~~~ # 长字符串 'foo\ bar' # 长表达式 'foo' * 2 + \ 'bar'\ ~~~ 禁止一行中多个语句 -------------------- ~~~ # 正确的写法 do_first() do_second() do_third() # 不推荐的写法 do_first();do_second();do_third(); ~~~ `if/for/while`一定要换行 ------------------------- ~~~ # 正确的写法 if foo == 'blah': do_blah_thing() # 不推荐的写法 if foo == 'blah': do_blash_thing() ~~~