类的专有方法(__getitem__和__setitem__)
# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#http://www.imooc.com/code/6252 #类的专有方法(__getitem__和__setitem__)
#__getitem__,返回给定键对应的值
#__setitem__,设置给定键对应的元素 class Test():
kk={}
def __getitem__(self,key):
return self.kk[key]
def __setitem__(self,key,value):
self.kk[key]=value test=Test()
test['fengmei']=25
print test['fengmei']# print test.__getitem__('fengmei')#
test.__setitem__('xiaodeng',28)
print test.__getitem__('xiaodeng')#
类的专有方法(__getitem__和__setitem__)的更多相关文章
- 4 python 类的专有方法介绍
1.__init__ : 构造函数,在生成对象时调用 该方法是在对象产生之后才会执行,只用来为对象进行初始化操作,可以有任意代码,但不一定有返回值. 所谓初始化构造函数就是在构造对象的同时被对象自动 ...
- [py]类的专有方法
陆陆续续总结一些用到的类的特殊方法 看源码总会看到一些奇奇怪怪的写法: 掺杂着设计模式 https://coding.net/u/RuoYun/p/Python-design-pattern/git/ ...
- 类的专有方法(__getattr__和__setattr__、__delattr__)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.360doc.com/content/15/0413/19/12067640_4629 ...
- 类的专有方法(__len__)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.imooc.com/code/6252 #类的专有方法(__len__) #如果一个类 ...
- 类的专有方法(__repr__)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://blog.csdn.net/yyt8yyt8/article/details/7030416 ...
- 类的专有方法(__del__)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.bubuko.com/infodetail-313791.html #类的专有方法(_ ...
- 类的专有方法(__init__)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.cnblogs.com/zyxstar2003/archive/2011/03/21/ ...
- 9.4、__del__、__doc__、__dict__、__module__、__getitem__、__setitem__、__delitem__、__str__、__repr__、__call__
相关内容: __del__.__doc__.__dict__.__module__.__getitem__.__setitem__.__delitem__.__str__.__repr__.__cal ...
- python干货-类属性和方法,类的方法重写
类属性与方法 类的私有属性 __private_attrs: 两个下划线开头,表明为私有,外部不可用,内部使用时self.__private_attrs. 类的方法 在类的内部,使用 def 关键字来 ...
随机推荐
- iOS中bundle的意义
什么是bundle? bundle就是一个文件夹,按照一定标准组织的目录结构.每个iOS APP至少有一个main bundle,这个main bundle包含了app的二进制代码及任何你用到的资源, ...
- SWT 全接触
http://www.ibm.com/developerworks/cn/opensource/os-swt/index.html 1.SWT简介 SWT-"Standard Widget ...
- 基于非比較的排序:计数排序(countSort),桶排序(bucketSort),基数排序(radixSort)
计数排序 条件:要排序的数组的元素必须是在一定范围的,比方是1~100.在排序之前我们必须知道数组元素的范围. 思路:顾名思义:就是用一个数组来计数的. 步骤: 1.用一个数组来计数count[ ], ...
- dlib landmark+人面识别
#include "stdafx.h" #include <dlib/image_processing/frontal_face_detector.h> #includ ...
- from __future__ import print_function
1.在python2.x的环境是使用下面语句,则第二句语法检查通过,第三句语法检查失败 from __future__ import print_function priint('good') pri ...
- Ubuntu下设置服务自启动
Ubuntu下设置服务自启动 一般/etc下可能还有/etc/rc.local,/etc/rc.sysinit文件,一般/etc/rc.local默认并不做什么实事,可能是系统留下的一个接口,供用户添 ...
- go语言基础之数组比较和赋值
1.go语音基础之数组比较和赋值 示例: package main //必须有个main包 import "fmt" func main() { //支持比较,只支持 == 或 ! ...
- jquery选择器的实现流程简析及提高性能建议!
当我们洋洋得意的使用jquery强大的选择器功能时有没有在意过jquery的选择性能问题呢,其实要想高效的使用jquery选择器,了解其实现流程是很有必要的,那么这篇文章我就简单的讲讲其实现流程,相信 ...
- IOS中键盘隐藏几种方式
在ios开发中,经常需要输入信息.输入信息有两种方式: UITextField和UITextView.信息输入完成后,需要隐藏键盘,下面为大家介绍几种隐藏键盘的方式. <一> 点击键盘上的 ...
- WebRequest多线程 超时问题
using System; using System.Collections; using System.Collections.Generic; using System.Net; using Sy ...