摘要:
__add__(self, other): 用于 + 操作符__sub__(self, other): 用于 - 操作符__mul__(self, other): 用于 * 操作符__truediv__(self, other): 用于 / 操作符__floordiv__(self, other): 阅读全文
摘要:
区别: +使用__add__函数,返回新地址 += 可变数据时使用__iadd__函数 ,返回原地址;不可变数据用__add__函数 不可变数据 #不可变数据 +和+= 都用__add__函数 i=10 i=i+2 print(id(i)) i+=2 print(id(i)) 可变数据 # 可变数据 阅读全文
摘要:
当类中没有__eq__函数时,根据地址比较 class Vector: def __init__(self, x, y): self.x = x self.y = y pos1=Vector(1,1) pos2=Vector(1,1) print(pos2==pos1) 自定义Vector类中没有_ 阅读全文
摘要:
单继承 在单继承中super主要是用来调用父类的方法的 class A: def __init__(self): self.n = 2 def add(self, m): print('self is {0} @A.add'.format(self)) self.n += m class B(A): 阅读全文
摘要:
客厅柜机遥控器 主卧空调遥控器 aa 阅读全文
摘要:
__dict__是用来存储对象属性的一个字典,其键为属性名,值为属性的值 class people: def __init__(self, id=0,name="",age=0): #初始化函数 #id是创建对象时要输入的参数 self.id = id #self.id 是对象属性 self.nam 阅读全文