发布时间:2019-09-15 09:56:49编辑:auto阅读(4705)
#!/usr/bin/python class Vector: def __init__(self, a, b): self.a = a self.b = b def __str__(self): return 'Vector (%d, %d)' % (self.a, self.b) def __add__(self,other): return Vector(self.a + other.a, self.b + other.b) v1 = Vector(2,10) v2 = Vector(5,-2) v3 = Vector(10,10) print v1 + v2 + v3 print v1
结果: Vector (17, 18) Vector (2, 10)
上一篇: Python 英文术语表
下一篇: python yield浅析
47846
46397
37285
34736
29317
25974
24918
19952
19548
18031
5794°
6419°
5930°
5963°
7066°
5912°
5947°
6440°
6405°
7782°