我是Python的新手。
我在Python 2.7上运行以下代码时,发现使用print或print()会产生不同的结果。这两个函数之间有什么区别?我阅读过其他类似问题的答案,例如这个问题,但没有找到我的答案。
class Rectangle:
def __init__(self, w, h):
self.width = w
self.height = h
def __str__(self):
return "(The width is: {0}, and the height is: {1})".format(self.width, self.height)
box = Rectangle(100, 200)
print ("box: ", box)
print "box: ", box
结果是:
('box: ', <__main__.Rectangle instance at 0x0293BDC8>)
box: (The width is: 100, and the height is: 200)