python运算符重载
生活随笔
收集整理的這篇文章主要介紹了
python运算符重载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
重載符模板代碼:
class Vector:def __init__(self, a, b):self.a = aself.b = bdef __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) print(v1 + v2)輸出:
Vector (7, 8)?
總結
以上是生活随笔為你收集整理的python运算符重载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C/C++语言函数学习(3)STL中ma
- 下一篇: OpenCV-Python bindin