Python3 字典

作者: Mrxiaowang | 来源:发表于2017-12-20 10:35 被阅读9次

dict= {}

dict['one'] ="this is one"

dict[2] ="this is two"

tinyDict = {'name':'john','code':6734,'dept':'sales'}

'''

print dict['one'] #输出键为'one'的值

print dict[2]#输出键为2

print tinyDict.keys() #输出所有jian

print tinyDict.values()#输出所有值

'''

#tinyDict.pop("name")#删除指定的

#print tinyDict

#tinyDict.popitem()#随机返回并删除字典中的一对键和值(一般删除末尾对)。

#print tinyDict

#tinyDict.setdefault("dfjfj","dfjiejfe") #和get()类似, 但如果键不存在于字典中,将会添加键并将值设为default

#print tinyDict

tinyDict.update(dict)#把字典dict的键/值对更新到tinyDict里

printtinyDict

相关文章

  • python合并字典

    python3和合并字典

  • python日常

    1. Python3中字典(dict)合并的几种方法 方法一:字典的update()方法 方法二:字典的dict(...

  • python3字典排序

    python3 字典排序 说实话,对字典进行排序,这个说法本身就有问题,实际上,你无法对操纵字典说,字典,在你的底...

  • Python字典学习笔记

    Python3 字典 定义 字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值(key=>value)...

  • Python 字典排序

    Python 字典排序 《Python3 CookBook》[https://python3-cookbook.r...

  • 001-Two Sum

    语言:python3 v1:轮询 结果:超时了,提交失败 v2:建立字典,循环字典 总结:字典映射结构比for循环效率更

  • Python3数据类型-04-字典

    Python3数据类型-字典-04 4.1 什么是字典(dict)? 字典同样是一种容纳多个元素的容器,在很多方面...

  • python3常见字典方法及代码解析

    本章将介绍 Python3字典类型常用的一些方法 update() 将一个字典所包含的键值对更新己有的字典中。如果...

  • Python3 字典

    字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值(key=>value)对用冒号(:)分割,每个对之...

  • Python3 字典

    dict= {} dict['one'] ="this is one" dict[2] ="this is two...

网友评论

    本文标题:Python3 字典

    本文链接:https://www.haomeiwen.com/subject/laawwxtx.html