One - One Code All

Blog Content

python为符合PEP8换行,一行拆多行

Python   2009-02-05 22:26:24

两种方法:反斜杠和括号。


1. 在一行末尾 加上“ \”,也就是空格加上\

  a= 'sdfaf' \
     'test'

注意:两个对象都要独立,字符串必须都用双引号引起。

如果是if and 后加“ \”。

2.用括号也可以,比如

a=('sdfaf'
'test')

或者

if (xxxx is None and

 xxx is None and

 XXX)

这样做效果是一样的。


上一篇:python风格PEP8报错:under-indented for visual indent
下一篇:python长字符串换行的三种方式

The minute you think of giving up, think of the reason why you held on so long.