如何将这样的作业分成两行?
myLongVariableName = 'some somewhat long format string like this %s' % myOtherVariable
我尝试了一些变化:
myLongVariableName = 'some somewhat long format string like this %s'
% myOtherVariable
myLongVariableName = 'some somewhat long format string like this %s' %
myOtherVariable
myLongVariableName =
'some somewhat long format string like this %s' % myOtherVariable
我的搜索时间很短。我发现的主要是谈论缩进代码块或参数块,而不是长表达式。
答案 0 :(得分:2)
相邻的字符串文字在Python中自动连接:
myLongVariableName = ('some somewhat long format'
'string like this %s') % myOtherVariable
答案 1 :(得分:2)
这是一个选项:
myLongVariableName = 'some somewhat long format string like this {}'
.format(myOtherVariable)
了解更多信息: https://docs.python.org/2/library/stdtypes.html#str.format