classPoint():def__init__(self, x, y):
self.x = x
self.y = y
print('Point constructor')
defToString(self):return"{{X: {},Y: {}}}".format(self.x, self.y)
–注意format时 ‘{{‘打印’{‘,’}}’打印’}’
'{{ {} {} {} }}'.format(1,2,3)
'{ 1 2 3 }'
p1 = Point(0.0, 0.0)
p1.ToString()
Point constructor
'{X: 0.0,Y: 0.0}'
classCircle(Point):'''
A circle is a point with radius.
'''def__init__(self, x, y, radius):
super().__init__(x, y) # call father's constructor
self.radius = radius
print('Circle constructor')
defToString(self):return super().ToString() + '{{RADIUS: {}}}'.format(self.radius)