我已经定义了这个类:
class Point():
def __init__(self,x,y):
self.x = x
self.y = y
def __str__(self):
return "Point x: {0}, Point y: {1}".format(self.x, self.y)
print("Point",p1)
这两种情况和有什么区别print(p1)
:
p1 = Point(1,2)
print("Point",p1)
print(p1)
>>('Point', <__main__.Point instance at 0x00D96F80>)
>>Point x: 1, Point y: 2