首页 > 解决方案 > Python中的隐含字符串连接

问题描述

我注意到当我像这样换行时,Pylance 没有给我一个错误:

>>> print('foo bar'
...   ' and then some.')
foo bar and then some.

我试过了,Python 似乎很乐意将这些连接起来,而且很简单:

>>> print('foo bar' 'and more')
foo barand more

我想我需要一个+来连接。这种行为是否可靠,或者我应该+用于换行,例如:

print('This is '
    + 'more readable.')

谢谢

标签: python

解决方案


推荐阅读