如何摆脱python输出中的\ n

时间:2015-03-09 12:31:36

标签: python

输入:

question1 = content[0],"\n",content[1]
print(question_order[0])

输出:

('How secret should you keep your passwords? \n', '\n', 'A)Never give out passwords except to your parents B)Give them only to your best friends C)Give them to strangers \n')

2 个答案:

答案 0 :(得分:0)

因为你对你的问题很模糊,这是我能做的最好的事情:

print([i.replace('\n', '') for i in question_order[0] if i.replace('\n', '') != ''])

答案 1 :(得分:0)

你的问题太模糊了。 如果content不是外部参考,并且是由您创建的,我建议在存储它们之前从数据中删除空格。

如果无法根据其定义删除content,建议您在将其附加到question1之前从已删除的值中question_order形成{假设,question_order是一个集合与question1)相同的类型。

question1 = content[0].strip(),"\n",content[1].strip()
print(question1)

将打印:

('How secret should you keep your passwords?', '\n', 'A)Never give out passwords except to your parents B)Give them only to your best friends C)Give them to strangers')