python类运算符的重载
2018-03-19 19:35
260 查看
alist = input().split() blist = input().split() n = float(input()) class Vector: def __init__(self, x=0, y=0, z=0): # 请在此编写你的代码(可删除pass语句) self.X = x self.Y = y self.Z = z # 代码结束 def __add__(self, other): return Vector(self.X + other.X, self.Y + other.Y, self.Z + other.Z) # 代码结束 def __sub__(self, other): return Vector(self.X - other.X, self.Y - other.Y, self.Z -other.Z) # 代码结束 def __mul__(self, other): return Vector(self.X * other, self.Y * other, self.Z * other) # 请在此编写你的代码(可删除pass语句) # 代码结束 def __truediv__(self, other): return Vector(self.X / other, self.Y / other, self.Z / other) # 请在此编写你的代码(可删除pass语句) # 代码结束 def __str__(self): # 请在此编写你的代码(可删除pass语句) return '(%.1f,%.1f,%.1f)' % (self.X, self.Y, self.Z) a = Vector(float(alist[0]), float(alist[1]), float(alist[2])) b = Vector(float(blist[0]), float(blist[1]), float(blist[2])) print(a + b, a - b, a * n, a / n)
相关文章推荐
- python运算符 供重载参考
- python 类的运算符及重载
- python中运算符“重载”
- python 运算符 重载可使用
- python 运算符 供重载参考
- python运算符 供重载参考
- python 运算符 供重载参考
- python运算符方法重载
- Python开发(基础):运算符
- 关于c++运算符重载 + 和 ++ 运算符 【2013.10.18】
- 【7.11】为Date类重载“+”运算符,实现在某一个日期上(月、日、年)加一个天数。
- python基础3——运算符
- Python中kill传送程序 signal HUP信号 程序重载配置文件
- python之基础篇(六)——表达式、语句和运算符
- C++ 流运算符的重载
- C++学习总结(十四)——类的运算符的重载原理,以及重载的实例
- python基础-列表,文件,运算符
- Python的运算符
- Python3 运算符
- python中的__init__函数重载与覆盖问题