python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返回元素个数 d[key] Return the item of d with key key. Raises a KeyError if key is not in the map. If a subclass of dict defines a method _missing_() and key
Google一下轻松找到了答案,大家可以看一下Python Wiki,很简单,翻译如下. 在Python中,当你使用a[key]这种方式从字典中获取一个值时,若字典中不存在这个此key时就会产生一个KeyError的错误,比如: In [1]: d = {'name': 'wang'} In [2]: d['name'] Out[2]: 'wang' In [3]: d['age'] --------------------------------------------------------
列表 如:[11,22,33,44,44].['TangXiaoyue', 'bruce tang'] 每个列表都具备如下功能: class list(object): """ list() -> new empty list list(iterable) -> new list initialized from iterable's items """ def append(self, p_object): # real signa
1.清空字典中元素清空,dict变为{} L.clear()-> None. Remove all items from L 1 2 3 4 >>> L ={'shaw':23,'sam':36,"eric":40} >>> L.clear() >>> print L {} 2. 返回一个字典的浅复制 L.copy()-> a shallow copy of L 1 2 3 >>> L ={'shaw