测量程序编制 - python 43数据类型:dict(字典)-扩展(一).pptxVIP

  • 1
  • 0
  • 约小于1千字
  • 约 5页
  • 2022-04-11 发布于江西
  • 举报

测量程序编制 - python 43数据类型:dict(字典)-扩展(一).pptx

数据类型:dict(字典)——扩展Dictionary(字典)——函数如果把一个字典对象作为for的迭代对象,那么这个操作将会遍历字典的键:a = {数学: 95, 语文: 89, 英语: 90}for i in a: print(i,end= )print()for i in a.keys(): print(i,end= )数学 语文 英语 数学 语文 英语 Dictionary(字典)——函数setdefault()方法:方法用来返回某个 key 对应的 value语法:dict.setdefault(key, default=None)key -- 查找的键值。default -- 键不存在时,设置的默认键值。返回值如果 key 在 字典中,返回对应的值如果不在字典中,则插入 key 及设置的默认值 default,并返回 default ,default 默认值为 None。Dictionary(字典)——函数setdefault()方法:dict = {Name: Python, Age: 7}print(Age 键的值为 : %s % dict.setdefault(Age, None))print (ID 值为 : %s % dict.setdefault(Id))print(Sex 键的值为 : %s % dict.setdefault(Sex,

文档评论(0)

1亿VIP精品文档

相关文档