#!/user/bin/python# -*- coding:utf-8 -*-dic1 = {‘age‘:24,‘name‘:‘zd‘,‘sex‘:‘boy‘}print(dic1)#增dic1[‘high‘] = 175 #没有建就添加dic1[‘sex‘] = ‘boy1‘ #有建就修改print(dic1)dic1.setdefault(‘weight‘,232) #有的话不做任何操作m没有的话就添加print(dic1)#删print(dic1.pop(‘age‘))#有返回值按键去删除print(dic1.pop(‘czxcxz‘,None))#可设置返回值print(dic1)dic1.popitem()#默认从最后删print(dic1)print(dic1.popitem())del dic1[‘name‘]print(dic1)dic1.clear() #清空print(dic1)#查dic1 = {‘age‘:24,‘name‘:‘zd‘,‘sex‘:‘boy‘}print(dic1.keys())print(dic1.values())print(dic1.items())for i in dic1: print(i)for k,v in dic1.items(): print(k,v)
原文地址:https://www.cnblogs.com/zhang-da/p/10205046.html
时间: 2024-11-05 20:39:40