image.png

类的实例化的调用过程

创建类的两种方法

  1. class Person(object): # 正常写法
  2. country = 'China'
  3. def __init__(self,name,age):
  4. self.name = name
  5. self.age = age
  6. def tell(self):
  7. print('%s 的年龄是:%s'%(self.name,self.age))
  1. country = 'China'
  2. def __init__(self,name,age):
  3. self.name = name
  4. self.age = age
  5. def tell(self):
  6. print('%s 的年龄是:%s'%(self.name,self.age))
  7. Person = type('Person',(object,),{'country':country,
  8. '__init__':__init__,
  9. 'tell':tell})
  10. # python 解释器 将第一种转化为第二种