Python:在三引号中键入制表符和\t 之间的区别

标签 python python-2.7 quotes

当用三重引号 """写一个字符串时,在字面上放入\n 或\t 换行或制表符,和在引号内​​按你想要的方式写它有什么区别? 例如:

sample = """ I'm writing this 
On separate lines
    And tabs
So why can't I write it like this
/t instead of tabbing like this
\n or new lining like this.
Is one way preferred over the other? """

是否首选一种方式?

最佳答案

请记住,明示比含蓄更好。使用特定的 \t\n 没有任何假设的余地。

关于Python:在三引号中键入制表符和\t 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21028316/

相关文章:

python - 无法 `pip install -r requirements.txt`

Python - 从字符串创建矩阵

python - 无法在 OpenCV 中展开图像

r - 如何阅读包含转义引号的引用文本

c# - 使用正则表达式在 C# 中查找带有转义引号的引用字符串

r - 如何从 R 中的字符串中删除单引号?

python - Pandas 从字符串中提取数字

python - 检查另一个列表中的字符串列表中是否存在字符串字符?

python - 更改默认的 tkinter Logo (python 2.7,Windows)

python - 将嵌套的json转换成没有嵌套对象的字典格式