【发布时间】:2016-07-21 23:18:37
【问题描述】:
我遇到了一个问题,如果我在 Windows 终端中运行我的 python 程序,带有插入变量的文本 (%s) 会产生古怪的结果,而在 python shell 中它可以正常工作。
代码:
print("Hi! What's your name?")
name = input("name: ")
print("Nice to meet you %s" % name)
print("%s is a good name." % name)
print("This line is only to test %s in the middle of the text." % name)
input("press enter to exit")
python shell 中的结果:
cmd 中的结果:
我使用的是 Windows 10 和 python32,以防你需要知道。
【问题讨论】:
-
这很有趣,请您使用
format代替%并发布结果吗? -
在 Win8.1 上对我来说很好。我从 Windows 命令行运行它,输出看起来就像你的 Python shell 结果。
-
在 Windows 7 下为我工作
标签: python shell python-3.x input cmd