How to remove unwanted single quotes

后端 未结 2 672
甜味超标
甜味超标 2021-01-24 13:19

I\'m new to programming and I stumbled across something unsightly that I would like to remove. Here\'s my code:

def test1():
    print \"What is your name, trave         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 13:50

    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.

提交回复
热议问题