类和正则表达(自动更正 代数运算)
Posted glzt
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类和正则表达(自动更正 代数运算)相关的知识,希望对你有一定的参考价值。
class V3: def_init_(self,x = 0,y = 0,z = 0): self.X = x self.Y = y self.Z = z def_add_(self,n): r = V3() r.X = self.X+n.X r.Y = self.Y+n.Y r.Z = self.Z+n.Z return r def_sub_(self,n): r = V3() r.X = self.X+(-n.X) r.Y = self.Y+(-n.Y) r.Z = self.Z+(-n.Z) return r def_mul_(self,n): r = V3() r.X = self.X*n r.Y = self.Y*n r.Z = self.Z*n return r def_truediv_(self,n): r = V3() r.X = self.X/n r.Y = self.Y/n r.Z = self.Z/n return r def_floordiv_(self,n): r = V3() r.X = self.X//n r.Y = self.Y//n r.Z = self.Z//n return r def show(self): print(self.X,self.Y,self.Z))
以上是关于类和正则表达(自动更正 代数运算)的主要内容,如果未能解决你的问题,请参考以下文章