python中哪个字符是用来续行的_Python样式 - 用字符串继续行?

在尝试遵守python样式规则时,我将编辑器设置为最多79列。

在PEP中,它建议在括号,括号和括号内使用python隐含的延续。 但是,当我达到col限制时处理字符串时,它会有点奇怪。

例如,尝试使用多行

mystr = """Why, hello there

wonderful stackoverflow people!"""

将返回

"Why, hello there\nwonderful stackoverflow people!"

这有效:

mystr = "Why, hello there \

wonderful stackoverflow people!"

因为它返回:

"Why, hello there wonderful stackoverflow people!"

但是,当语句缩进几个块时,这看起来很奇怪:

do stuff:

and more stuff:

and even some more stuff:

mystr = "Why, hello there \

wonderful stackoverflow people!"

如果您尝试缩进第二行:

do stuff:

and more stuff:

and even some more stuff:

mystr = "Why, hello there \

wonderful stackoverflow people!"

你的字符串最终为:

"Why, hello there wonderful stackoverflow people!"

我发现解决这个问题的唯一方法是:

do stuff:

and more stuff:

and even some more stuff:

mystr = "Why, hello there" \

"wonderful stackoverflow people!"

我觉得哪个更好,但眼睛也有些不安,因为看起来有一根绳子只是坐在不知名的地方。 这将产生适当的:

"Why, hello there wonderful stackoverflow people!"

所以,我的问题是 - 关于如何做到这一点的一些人的建议是什么?在样式指南中是否有我缺少的东西,它确实显示了我应该如何做到这一点?

谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值