定义类
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "{} and {}".format(self.x, self.y)
def show(self):
print(self.x, self.y)
dict
>>> p = Point(4, 5)
>>> print(p)
4 and 5
>>> print(p.__dict__)
{'x': 4, 'y': 5}
>>> p.__dict__['y'] = 16
>>> print(p.__dict__)
{'x': 4, 'y': 16}