How to remove unwanted single quotes

孤人 提交于 2019-12-02 07:44:09
ron rothman

You want to use %s there, not %r.

print "Hi %s!" % (name)

I'd add details, but I think others have already written better explanations here and here.

Most saliently:

The difference between %s and %r is that %s uses the str function and %r uses the repr function. You can read about the differences between str and repr in this answer, but for built-in types, the biggest difference in practice is that repr for strings includes quotes and all special characters are escaped.

Or use the "new" string formatting method:

def test1():
print "What is your name, traveler?"
name = raw_input()
print "Hi {0}!".format(name)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!