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. [原]osg模型动画|骨骼动画

    参考源码:osg的官方例子:osganimationviewer 首先制作一个带骨骼动画的模型  demo.FBX 这里面我们做了两个骨骼动画:1.open   2.close 下面开始在osg中使用 ...

  2. 使用npm私有服务器保存公司内部强业务类型组件(三):关于业务性组件的一点思考

    编写业务性组件最难的地方不在于技术,而在于沟通, 1:前端将业务给封装了起来,必然导致产品在设计的时候多了一层考虑,在新增功能的时候 他要考虑这个功能是不是在其他项目也需要,如果不是的话,就不应该放在 ...

  3. diango admin 添加成员报错

    [报错内容]: IntegrityError at /admin/users/userprofile/add/ (1452, 'Cannot add or update a child row: a ...

  4. mysql5.7.25安装

    附:mysql安装包 链接:https://pan.baidu.com/s/1vROdBSw0GiMWCRpuwmqFCg 提取码:ug4o a.运行mysql-installer-community ...

  5. ASP.NET Razor - 标记

    目录 什么是 Razor? Razor 帮助器 ASP.NET Razor - C# 和 VB 代码语法 主要的 Razor C# 语法规则 它是如何工作的? 使用对象 If 和 Else条件 读取用 ...

  6. Response.End ,Response.Redirect、Server.Transfer 引发 “正在中止线程”异常的问题

    google后得知:Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件,同时抛出ThreadAbortExcepti ...

  7. 服务定位器(Service Locator)

    服务定位器(Service Locator) 跟DI容器类似,引入Service Locator目的也在于解耦.有许多成熟的设计模式也可用于解耦,但在Web应用上, Service Locator绝对 ...

  8. linux 下的read write 和fread fwrite

    待进一步测试啊,先占坑 --------2017/7/17 忘记之前要写什么了,只记得当时测试完得出的结论是,无论是写设备还是写文件,都用read/write是既安全又省事情的举动.还熟悉. 尽多少力 ...

  9. AS3.0 给addEventListener里的方法加上参数传递

    方法一:for(var i:int=1;i<=4;i++){this["btn"+i].addEventListener(MouseEvent.CLICK,EventUp(b ...

  10. crontab 每分钟、每小时、每天、每周、每月、每年执行

    每分钟执行 * * * * * 每小时执行 0 * * * * 每天执行 0 0 * * * 每周执行 0 0 * * 0 每月执行 0 0 1 * * 每年执行 0 0 1 1 * 每小时的第3和第 ...