带双下划线的特殊方法

  1.   __init__()       类名() 会⾃动执⾏
  2.    __call__()    对象() 会⾃动执⾏
  3.   __str__()      print对象的时候 会⾃动执⾏
  4.   __add__()    对象+对象 会⾃动执⾏
  5.   __getitem__()   对象[key] 会⾃动执⾏
  6.   __setitem__()   对象[key] = value 会⾃动执⾏
  7.   __delitem__()    del 对象[key] 会⾃动执⾏
  8.   __enter__ 和__exit__        with 对象 as 变量 会⾃动执⾏
  9.   __hash__ == None  对象就不可哈希了



原文:https://blog.csdn.net/weixin_43976393/article/details/87996190

posted @ 2019-06-01 15:43  bin-y  阅读(192)  评论(0编辑  收藏  举报