码迷,mamicode.com
首页 > 其他好文 > 详细

类和正则表达(自动更正 代数运算)

时间:2020-05-06 18:17:51      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:elf   sel   表达   show   自动   pytho   init   add   python   

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))

  

类和正则表达(自动更正 代数运算)

标签:elf   sel   表达   show   自动   pytho   init   add   python   

原文地址:https://www.cnblogs.com/Glzt/p/12837739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!