sur*_*190 12 python string python-3.x f-string
我得到了一个line too longpep8 E501问题.
f'Leave Request created successfully. Approvers sent the request for approval: {leave_approver_list}'
Run Code Online (Sandbox Code Playgroud)
我尝试使用多行字符串,但这带来了一个\n,这打破了我的测试:
f'''Leave Request created successfully.
Approvers sent the request for approval: {leave_approver_list}'''
Run Code Online (Sandbox Code Playgroud)
如何保持单线并通过pep8linting
jua*_*aga 15
使用括号和字符串文字串联:
msg = (
f'Leave Request created successfully. '
f'Approvers sent the request for approval: {leave_approver_list}'
)
Run Code Online (Sandbox Code Playgroud)
注意,第一个文字不需要f,但我包含它是为了一致性/可读性.
cs9*_*s95 12
除非您将字符串括在括号内,否则您将需要换行符。在这种情况下,f将需要添加到第二行:
'Leave Request created successfully.'\
f'Approvers sent the request for approval: {leave_approver_list}'
Run Code Online (Sandbox Code Playgroud)
这是一个小演示:
In [97]: a = 123
In [98]: 'foo_'\
...: f'bar_{a}'
Out[98]: 'foo_bar_123'
Run Code Online (Sandbox Code Playgroud)
我推荐 juanpa 的答案,因为它更干净,但这是一种方法。
| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |