如何摆脱 Python raw_input() 中的正斜杠

发布于 2024-11-02 11:27:57 字数 252 浏览 5 评论 0原文

这里是初学者程序员。所以请耐心听我说。我有一个简单的 python 程序。

print "How tall are you?",
height = raw_input()

print "So you're %r tall" %(height)

如果我输入高度为 6'6'' python 将输出

So you're '6\6"'

如何从输出中删除正斜杠“\”?

提前致谢!

Beginner programmer here. So bear with me. I have a simple python program.

print "How tall are you?",
height = raw_input()

print "So you're %r tall" %(height)

If I enter the height as 6'6'' python would output

So you're '6\6"'

How do I get rid of the forward slash "\" from the output?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-11-09 11:27:57

%r 转换为高度的表示,你应该使用 %s 代替

如果你使用的是 Python >=2.6,你可以这样写

print "So you're {height} tall.".format(height=height)

%r converts to the repr of height, you should use %s instead

If you are using Python >=2.6, you can write it this way instead

print "So you're {height} tall.".format(height=height)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文