Don';我不想在python代码中使用单引号
我正在使用Python 2.7。。。我面临的问题是当我使用此代码时Don';我不想在python代码中使用单引号,python,python-2.7,python-2.x,Python,Python 2.7,Python 2.x,我正在使用Python 2.7。。。我面临的问题是当我使用此代码时 print "How old are you?", age = raw_input() print "How tall are you?", height = raw_input() print "How much do you weigh?", weight = raw_input() print "So, you're %r old, %r tall and %r heavy." % (
print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % (
age, height, weight)
结果是-
How old are you? 35
How tall are you? 6'2"
How much do you weigh? 180lbs
So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
但我不希望输出的第四行中出现35180磅和6.2英寸左右的单引号。如何做不要使用
%r
。更改:
print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight)
致:
repr()
以下是解释器中的一个示例:
>>> print '%r' % 'Hi'
'Hi'
>>> print '%s' % 'Hi'
Hi
>>>
>>>打印“%r%”嗨
“嗨”
>>>打印“%s”%”嗨
你好
>>>
看看学生们常见的问题:Zed通常会回答这样的问题,他当然会回答这样的问题。
>>> print '%r' % 'Hi'
'Hi'
>>> print '%s' % 'Hi'
Hi
>>>