(1)实例可以随意添加属性
(2)某个实例绑定的方法对另一个实例不起作用
(3)给类绑定方法市所有类都绑定了该方法,且所有实例都可以调用该方法
>>> class student(object): __slots__=("name","age") >>> s=student() >>> s.name="jack" >>> s.score=90 traceback (most recent call last): file "<pyshell#43>", line 1, in <module> s.score=90 attributeerror: 'student' object has no attribute 'score'
@property是python内置的装饰器
>>> class student(object): @property def test(self): return self.name @test.setter def test(self,name): self.name=name >>> s=student() >>> s.test="alice" >>> print(s.test) alice
通过多重继承,子类可以同时获得多个父类的所有功能
>>> class run(object): def run(): print("i can run.") >>> class fly(object): def fly(): print("i can fly.") >>> class swim(object): def swim(): print("i can swim.") >>> class duck(run,fly,swim): pass
mixln:允许使用多重继承的设计
如对本文有疑问, 点击进行留言回复!!
Python限制内存和CPU使用量的方法(Unix系统适用)
网友评论