【发布时间】:2016-05-27 11:41:29
【问题描述】:
print、object 和 repr() 有什么区别?
为什么它以不同的格式打印?
见output difference:
>>> x="This is New era"
>>> print x # print in double quote when with print()
This is New era
>>> x # x display in single quote
'This is New era'
>>> x.__repr__() # repr() already contain string
"'This is New era'"
>>> x.__str__() # str() print only in single quote ''
'This is New era'
【问题讨论】:
-
我认为名称 x 附加到“这是新时代”字符串。例如,当我调用 repr(x) 时,iterpreter 会输入 'This is New era' 而不是 x,然后调用 repr('This is New era')。