如何在python 2.7中使用转义序列

时间:2017-02-07 03:47:06

标签: python-2.7

我正在使用python 2.7.13而且我是初学者。

我的方案是转义序列在命令提示符下无法正常工作,我附上了一张图片,请有人告诉我我的代码有什么问题吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

如果使用转义序列,则表示'/ n',这是因为您使用print函数打印值列表/元组。

如果您使用字符串格式,它将为您提供所期望的内容:

print("Your amount %s consists of \n%s dollars\n" % (amount, totaldollars))

%s是一个占位符,就像大多数其他语言一样。变量“amount”和“totaldollars”从'%'另一侧的元组中取代

相关问题