python - 长字符串的 Python 外观转义
问题描述
我有一些愚蠢的东西让我很烦。使用 flake8 linter,他们显然喜欢短线,如果我运行如下字符串继续下一行:
print('\nWe interrupt this program to annoy you and make things \
generally more irritating.\n')
这是打印的:
We interrupt this program to annoy you and make things generally more irritating.
在打印输出之间没有大空间的情况下继续一行代码的正确方法是什么?
解决方案
这有效:
print("\nWe interrupt this program to annoy you and make things "
"generally more irritating.\n")
你不需要任何继续。只需将两个字符串放在一起,中间没有任何内容,Python 解析器就会知道连接它们的意思
这称为字符串文字连接
推荐阅读
- matrix - How to store symbolic matrix in Octave?
- mysql - Mysql在不包括相同值的值之间选择
- typescript - babel 7 在与 typescript 插件一起使用时不会转译
- react-native - React Native Expo Notification
- django - django 2.1.3 'django.db.backends.postgis' 不是可用的数据库后端
- rabbitmq - How to guarantee message order in RabbitMQ (or any other asynchronous message queue service)
- list - Prolog check if first element in lists are not equal and second item in list is equal
- reactjs - typescript that said has no exported member MyModule
- python - Using list comprehensions, transform all vowels within a string to upper case?
- r - 来自日期数据框的每月时间趋势