码迷,mamicode.com
首页 > 其他好文 > 详细

类的特殊成员方法

时间:2018-11-27 22:55:23      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:执行   __call   self   call   特殊   *args   rgs   ini   cal   

 

class Foo():

  def __init__(self):

    print(‘init‘)

  def __call__(self,*args,**kwargs)

    print(‘call‘)

  def __getitem__(self,item):

    print(item)

  def __setitem__(self,key,value)

    print(key,value)

  def __delitem__(self,item)

    print(key)

 

r = Foo()  # 执行__init__ 方法

r()            # 执行 __call__方法

r[‘keyee’]            # 执行 __getitem__方法

r[‘key1‘] = 123    # 执行 __setitem__方法

del r[‘key2‘]        # 执行 __delitem__方法

 

类的特殊成员方法

标签:执行   __call   self   call   特殊   *args   rgs   ini   cal   

原文地址:https://www.cnblogs.com/huangguabushihaogua/p/10029477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!