反射(重点)

1. isinstance, type, issubclass
  isinstance: 判断你给对象是否是xx类型的. (向上判断)
  type: 返回xxx对象的数据类型
  issubclass: 判断xxx类是否xxx的子类

2. 如何区分方法和函数(代码)
  在类中:
  实例方法
    如果是   类名.方法      是函数
    如果是   对象.方法      是方法


  类方法:

    都是方法


  静态方法:

     都是函数

  from types import MethodType, FunctionType
  isinstance()


3. 反射(重要)
  一共就4个函数
  attr: attribute

  getattr()     (重要)
    从xxx对象中获取到xxx属性值
  hasattr()     (重要)
    判断xxx对象中是否有xxx属性值
  delattr()
    从xxx对象中删除xxx属性
  setattr()
    设置xxx对象中的xxx属性为xxxx值

猜你喜欢

转载自www.cnblogs.com/gyc-tzx/p/10150834.html
今日推荐