相关疑难解决方法(0)

用Python包裹长行

如何在不牺牲缩进的情况下在Python中包装长行?

例如:

def fun():
    print '{0} Here is a really long sentence with {1}'.format(3, 5)
Run Code Online (Sandbox Code Playgroud)

假设这超过了79个字符的建议限制.我读它的方式,这里是如何缩进它:

def fun():
    print '{0} Here is a really long \
sentence with {1}'.format(3, 5)
Run Code Online (Sandbox Code Playgroud)

但是,使用这种方法,连续行的缩进与缩进相匹配fun().这看起来有点难看.如果有人要查看我的代码,那么由于这个print陈述而导致缩进不均匀会很糟糕.

如何在不牺牲代码可读性的情况下有效地缩进这样的行?

python string

192
推荐指数
6
解决办法
22万
查看次数

标签 统计

python ×1

string ×1