【发布时间】:2021-06-17 12:48:07
【问题描述】:
下面是我需要格式化的字符串内容:
输入:
input = 'This is line_number_1 \n \t This is second line with a tab \n \t\t This is third line with two tabs'
print(input) #This results like below,
'This is line_number_1 \n \t This is second line with a tab \n \t\t This is third line with two tabs'
但预期的输出:
'This is line_number_1
This is second line with a tab
This is third line with two tabs'
预期应该是一个字符串,而不是使用 Python 的行列表
【问题讨论】:
-
您的问题是什么?如果您打印输入,您将获得输出。
-
当我将它存储在一个字符串中时,我仍然可以看到 \n 和 \t
-
input是内置函数,请勿用作名称。同样,当您print(input)时,它将产生所需的输出,而不是您显示的内容
标签: python python-3.x string replace line