python - 我如何知道在Python中添加多少个反斜杠

标签 python

Why I need to add 5 backslash on the left if I want to show three of them in Python? How to count the backslash?

# [ ] print "\\\WARNING!///"
print('"\\\\\Warning///"')

最佳答案

您可以通过添加r来使用“原始字符串”:

print(r'"\\\Warning///"')

这有助于避免反斜杠的“转义”属性,Python 使用该属性来控制特殊字符的使用

关于python - 我如何知道在Python中添加多少个反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45452219/

相关文章:

python - 如何将鼠兔连接到rabbitMQ远程服务器? ( python 、鼠兔)

python - Feedparser Python : Is there a way to handle connection errors?

python - Basemap能否绘制城市级别的详细海岸线?

python - 有没有适用于 Python 3.0 的图形/绘图/类似库?

python - 如何使用aubio获取python中一系列音调中每个音调的频率

python - Elasticsearch 6.7.0 嵌套 "bool", "should","must"查询

python - 使用指标 'acc' 和 tf.keras.metrics.Accuracy() 有什么区别

python - 从列表中删除 n 多个项目

python - scipy.optimize : how to restrict argument values

python - os.environ 不返回新的和导出的环境变量