python-day18

一. issubclass, type, isintance

  issubclass  判断xxx类是否是xxx类的子类

  type  获取到xxx对象的类型

  isinstance  判断xxx对象是否是xxx类型的(向上判断)

二. 如何判断一个方法或者一个函数(FunctionType,MethodType)

  from types import FunctionType,MethodType

  print(isinstance(xx,FunctionType))

  print(isinstance(xx,MethodType))

  结论:

    1. 实例方法:

      用类名访问.  函数

      用对象访问.  方法

    2. 静态方法

      都是函数

    3. 类方法

      都是方法

三. 反射(重点)

  hasattr(对象,属性(字符串))

  getattr(对象,属性(字符串))  从对象中获取到xxx属性

  

  setattr(对象, 属性, 值)

  delattr(对象, 属性)  从对象中删除xxx属性

四. md5 加密

  import hashlib

  obj = hashlib.md5(加盐)

  obj.update(铭文的bytes)

  obj.hexdigest() 获取密文

猜你喜欢

转载自www.cnblogs.com/Thui/p/9936281.html