class Foo:
def __getitem__(self, item):
print('getitem',item)
return self.__dict__[item]
def __setitem__(self, key, value):
print('setitem')
self.__dict__[key]=value
def __delitem__(self, key):
print('delitem')
self.__dict__.pop(key)
f1= Foo()
print(f1.__dict__)
f1['name']='egon'
f1['age']=19
print('=====>',f1.__dict__)

  

__getattitem_ \__setattitem__\__delitem__的更多相关文章

  1. Python的魔法函数之 - __len__,__getitem__,__setitem__,__delitem__

    # 对象作为len()函数的参数是必须实现该方法 __len__ # 使用类似字典方式访问成员时必须实现 dic['pro_name'] __getitem__ # 使用类似字典方式设置成员时必须实现 ...

  2. __delattr__\__delitem__

    class Foo: def __init__(self,name): self.name=name def __getitem__(self, item): print(self.__dict__[ ...

  3. python 魔法方法之:__getitem__ __setitem__ __delitem__

    h2 { color: #fff; background-color: #7CCD7C; padding: 3px; margin: 10px 0px } h3 { color: #fff; back ...

  4. python中的__len__,__getitem__ __setitem__ __delitem__ __contains__

    可变集合需要实现: __len__  __getitem__    __setitem__  __delitem__不可变集合需要实现: __len__  __getitem__ __len__:返回 ...

  5. __getitem__ __setitem__ __delitem__ 使用

    #__getitem__ __setitem__ __delitem__运行设置key value值了class fun: def __init__(self): print('test') def ...

  6. 9.4、__del__、__doc__、__dict__、__module__、__getitem__、__setitem__、__delitem__、__str__、__repr__、__call__

    相关内容: __del__.__doc__.__dict__.__module__.__getitem__.__setitem__.__delitem__.__str__.__repr__.__cal ...

  7. __getitem__()、__setitem__()与__delitem__()

    # 如果想要运用[]取值,可以实现__getitem__() # 想要运用[]设值,可以实现__setitem__() # 若想通过del与[]来删除,可以实现__delitem__() class ...

  8. python基础----__setitem__,__getitem,__delitem__

    class Foo: def __init__(self,name): self.name=name def __getitem__(self, item): print(self.__dict__[ ...

  9. Python类,特殊方法, __getitem__,__len__, __delitem__

    特殊函数一般以__methodname__的形式命名,如:__init__(构造方法), __getitem__. __setitem__(subscriptable所需method), __deli ...

随机推荐

  1. Intent属性详解二 Action、Category

    先看效果图: 1.Action:该activity可以执行的动作 该标识用来说明这个activity可以执行哪些动作,所以当隐式intent传递过来action时,如果跟这里<intent-fi ...

  2. UITableView或UIScrollVIew上的UIButton的高亮效果

    UITableView或UIScrollVIew上的UIButton的高亮效果 原文地址:http://www.jianshu.com/p/b4331f06bd34 最近做项目的时候发现,UIScro ...

  3. idea使用优化常用快捷键设置

    1. 界面美观 1.1. 主题 1.2. 改Project面板大小 2. 快捷键 2.1智能提示 2.2常用快捷键 3.编辑器调整 3.1 代码提示忽略大小写 3.2 显示行号 3.3 优化自动导入 ...

  4. iOS --NSAttributedString

    字符属性可以应用于 attributed string 的文本中. 文/iOS_成才录(简书作者) 原文链接:http://www.jianshu.com/p/03a741246737 著作权归作者所 ...

  5. 开发者调试工具Chrome Workspace

    Workspace是个什么样的东西呢?他能够在开发者工具中调试修改js或者css同时自动保存文件,能够避免开发人员在工具中调试好,再到编辑器中修改一次代码的重复操作,能够提高一定的效率 配置Chrom ...

  6. 记一道有意思的算法题Rotate Image(旋转图像)

    题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an ...

  7. 使用Echarts实现动态曲线图表

    最近做的一个在线气象观测网站要实现一个需求:使用图表展示最近五天温湿度等气象要素的曲线变化 具体效果参考:http://www.weatherobserve.com/showInfoIndex.jsp ...

  8. 【转】Hive 基础之:分区、桶、Sort Merge Bucket Join

    Hive 已是目前业界最为通用.廉价的构建大数据时代数据仓库的解决方案了,虽然也有 Impala 等后起之秀,但目前从功能.稳定性等方面来说,Hive 的地位尚不可撼动. 其实这篇博文主要是想聊聊 S ...

  9. 廖雪峰python教程的第一个疑问

    函数的参数一节中提到: def add_end(L = []); L.append('END') return L 正常调用add_end时(也就是有参数传入时): >>> add_ ...

  10. log4j2 不使用配置文件,动态生成logger对象

    大家平时使用Log4j一般都是在classpath下放置一个log4j的配置文件,比如log4j.xml,里面配置好Appenders和Loggers,但是前一阵想做某需求的时候,想要的效果是每一个任 ...