Discuss / Python / type()的一些小小的感悟,自己体会得来!

type()的一些小小的感悟,自己体会得来!

Topic source

神月宗

#1 Created at ... [Delete] [Delete and Lock User]

def fn(self,name = "world"): print "hello,%s"%name

class Animal(object): @property def ani(self): print "Animal" class Fly(Animal): @property def fly(self): print "Fly" class Dog(Animal): @property def dog(self): print "Dog" class Bat(Fly): pass

#这个class 名称是不是必须跟类名一样?

#我测试过!不一定,但是最好写一样吧! Test = type("Test",(Fly,Animal),dict(hello = fn))

#继承多重父类,可调用继承的属性! h = Test() h.hello() h.ani h.fly

#h.dog() 非继承不可调用!


  • 1

Reply