1、动态语言
class animal:
def eat(self):
print('animal will eat')
class dog(animal):
def eat(self):
print('dog is eating bone')
class cat(animal):
def eat(self):
print('cat is eating fish')
class person:
def eat(self):
print('people is eating corn')
def fun(obj):
obj.eat()
fun(animal)
fun(dog())
fun(cat())
fun(person())
2、特殊属性和特殊方法
class A:
pass
class B:
pass
class C(A,B):
def __init__(self,name,age):
self.name=name
self.age=age
x=C('cecilia',1)
print(x.__dict__)
print(C.__dict__)
print(x.__class__)
print(C.__bases__)
print(C.__base__)
print(C.__mro__)
print(A.__subclasses__())
class Student:
def __init__(self,name):
self.name=name
def __add__(self,other):
return self.name+other.name
def __len__(self):
return len(self.name)
stu1=Student('Ann')
stu2=Student('Jack')
print(stu1+stu2)
s=stu1.__add__(stu2)
print(s)
print(len(stu1))
标签:__,name,Python,self,day15,print,class,def
From: https://blog.51cto.com/u_16080683/7570149