'''
数据类型划分,可变数据类型 不可变数据类型
不可变数据类型,元组,bool,int,str 可哈希
可变数据类型, list, dict,set 不可哈希
dict key必须是不可变数据类型,可哈希
value ,任意数据类型。
dict 优点:二分查找去查询
存储大量关系型数据
特点 : 无序
'''
dic1 = {"name":"jin","age":18,"sex":"male"}
#增:
dic1['high'] = 185 #没有键值对,添加
dic1['high'] = 185 #如果有建,覆盖
print(dic1)
dic1.setdefault('weight') #有键值对,不做任何改变,没有才添加。
dic1.setdefault('weight',150)
print(dic1)
#删
# dic1.pop('age')
print(dic1.pop('age')) #有返回值,按键去删除
print(dic1.pop('二哥',None)) #可设置返回值
print(dic1)
print(dic1.popitem()) #随机删除,但是3.6是有顺序的,删除最后一个。返回一个元祖。
print(dic1)
dic1.clear()
print(dic1)
# del dic1
# print(dic1)
dic1 = {"name":"jin","age":18,"sex":"male"}
dic2 = {"name":"jingg","age":19,"sex":"female"}
# dic2 = {'name':'zhang','age':19,'weight':'lisi'}
dic1.update(dic2)
print(dic1)
print(dic2)
#查
dic1 = {"name":"jin","age":18,"sex":"male"}
print(dic1.keys(),type(dic1.keys()))
print(dic1.values())
print(dic1.items())
for i in dic1:
print(i)
for i in dic1.keys():
print(i)
for i in dic1.values():
print(i)
#可以一次使用两个变量接收
for i,j in dic1.items():
print(i,j)
v1 = dic1['name'] #可以查值,如果没有则会报错
print(v1)
#a,b,交换数值
a,b = 1,2
a,b = b,a
print(a,b)
dic1 = {"name":"jin","age":18,"sex":"male"}
print(dic1.get('name1','没有这个键'))
dic1["age"] = 19
print(dic1)
#fsdshdi93486734asnsuas43897dshi
info = input('>>>').strip()
for i in info:
if i.isalpha():
info = info.replace(i,' ')
l = info.split()
print(len(l))