def clear(self): # 清除所有内容
""" D.clear() -> None. Remove all items from D. """
pass def copy(self): # 浅复制
""" D.copy() -> a shallow copy of D """ def fromkeys(*args, **kwargs): # real signature unknown
""" Returns a new dict with keys from iterable and values equal to value. """
pass def get(self, k, d=None): # 根据字典的key获取值,如果key不存在,返回None。
""" D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None. """
pass def items(self): # 获取字典所有的键值对
""" D.items() -> a set-like object providing a view on D's items """
pass
example:
  dic = {
    1: 'abc',
2: 'def',
3: 'hjk'
} for k,v in dic.items():
print(k,v)  

  1 abc    #返回结果
  2 def
  3 hjk


def keys(self): # 获取字典所有的key
""" D.keys() -> a set-like object providing a view on D's keys """
pass def pop(self, k, d=None): # 获取并在字典中移除,可指定移除。
"""
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
"""
pass def popitem(self): # 获取并在字典中移除,只能从尾部移除。
"""
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty.
"""
pass def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
""" D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D """
pass def update(self, E=None, **F): # 批量更新
"""
D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
"""
example:
  dic = {
    1: 'abc',
2: 'def',
3: 'hjk'
  }   test = {
4: 'lmn',
5: 'opq'
  }
  dic.update(test)
  print(dic)
    {1: 'abc', 2: 'def', 3: 'hjk', 4: 'lmn', 5: 'opq'}  #返回结果

def values(self): # 获取字典所有的值
""" D.values() -> an object providing a view on D's values """
pass

Python之字典方法的更多相关文章

  1. Python dict字典方法完全攻略(全)

    我们知道,Python 字典的数据类型为 dict,我们可使用 dir(dict) 来查看该类型包含哪些方法,例如: >>> dir(dict)['clear', 'copy', ' ...

  2. python 通用字典方法

    版本1 方法 # 不传返回所有属性,传入props只返回传入的对应属性 def m_dict(obj, props=[]): result = {} target = obj else props f ...

  3. Python——字典与字典方法

    字典是一种通过名字或者关键字引用的得数据结构,其键可以是数字.字符串.元组,这种结构类型也称之为映射.字典类型是Python中唯一內建的映射类型,基本的操作包括如下: (1)len():返回字典中键— ...

  4. Python基础 第四章 字典(2)字典方法&章小结

    1. clear 方法clear删除所有的字典项,就地执行,什么都不返回(或者说返回None) d = {} d['name'] = 'Gumby' d['age'] = 42 print(d) re ...

  5. python将字典列表导出为Excel文件的方法

    将如下的字典列表内容导出为Excel表格文件形式: ​ 关于上图字典列表的写入,请参考文章:https://blog.csdn.net/weixin_39082390/article/details/ ...

  6. Python常用数据结构-字典——2.1 字典方法 keys()

    python字典常用方法: keys()               #  获取所有的键 values()            #  获取所有的值 items()              #  获 ...

  7. Python 迭代器 & __iter__方法

    转载来自: http://blog.csdn.net/bluebird_237/article/details/38894617 迭代器就是重复地做一些事情,可以简单的理解为循环,在python中实现 ...

  8. Python中sorted()方法

    Python中sorted()方法的用法 1.先说一下iterable,中文意思是迭代器. Python的帮助文档中对iterable的解释是:iteralbe指的是能够一次返回它的一个成员的对象.i ...

  9. python类及其方法

    python类及其方法 一.介绍 在 Python 中,面向对象编程主要有两个主题,就是类和类实例类与实例:类与实例相互关联着:类是对象的定义,而实例是"真正的实物",它存放了类中 ...

随机推荐

  1. 论文笔记:Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells

    Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells 2019-04- ...

  2. [转载]使用IEDriverServer.exe驱动IE11,实现自动化测试

    转自:https://www.cnblogs.com/feiquan/p/8531618.html 下载地址: http://dl.pconline.com.cn/download/771640-1. ...

  3. selenium python 中浏览器操作

    1.启用浏览器 browser = webdriver.Chrome()               谷歌浏览器 browser = webdriver.Firefox()              ...

  4. Go-For Range 性能研究

    文章转载地址:https://www.flysnow.org/2018/10/20/golang-for-range-slice-map.html 如果我们要遍历某个数组,Map 集合.Slice 切 ...

  5. Codeforces 803C. Maximal GCD

    题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这 ...

  6. Qt551.窗口滚动条

    1.代码的方式来创建 ScrollArea,然后使用 倒是 正常(有滚动条显示),但是此方式太麻烦 不如直接拖控件来的方便直观快捷. 但是,直接拖控件的方式 ScrollArea中无法显示出 滚动条, ...

  7. Halcon 标定与准确测量

  8. layui

    给大家推荐个比较好用的前端ui框架layui,遵循原生HTML/CSS/JS的书写与组织形式,门槛极低,拿来即用,而且layui除了ie6/7不兼容其他都兼容,而且还是响应式布局 1,获得layui后 ...

  9. YARN详解

    1.1      分布式资源调度框架 1.2.1          yarn的概念 Apache Hadoop YARN (Yet Another Resource Negotiator,另一种资源协 ...

  10. C++学习建议

    C++学习建议 C++缺点之一,是相对许多语言复杂,而且难学难精.许多人说学习C语言只需一本K&R<C程序设计语言>即可,但C++书籍却是多不胜数.我是从C进入C++,皆是靠阅读自 ...