# Auther: Aaron Fan

info = {
"stull01":"alen zhang",
"stull02":"si li",
"stull03":"san zhang",
}

#查
print(info)
print(info["stull01"])
print(info.get("stull04")) #有就返回它的值,没有就为None
print("stull03" in info) #判断一个键是否在一个字典里面,有就True没有就False
#python2.7里面有一个和这个效果一模一样的用法:info.has_key("stull03"),这个方法只适用python2,python3里面已经没有这种方法了,注意一下就行了


#改
info["stull02"] = "李四"
print(info)

#增
info["stull04"] = "小王"
print(info)

#删
del info["stull04"] #注意永久性的删除
info.pop("stull03") #弹出,跟列表里面的pop用法一样,可以去参考一下
test1 = info.popitem() #随机弹出
print(info)
print(test1)

相关文章:

  • 2018-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-11-07
猜你喜欢
  • 2018-01-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-05-24
相关资源
相似解决方案