元组
不能修改,只能合并,用小括号()表示
corse1=(1,2,5) corse2=(5,8,0)
corse3=corse1+corse2
print(corse3)
输出:corse3=(1,2,5,5,8,0)
字典
功能强大,可以增删改查,用大括号{}表示。
格式:d={key1:value1,key2:value2,key3:value3}
特点:键是唯一的,值可以重复,键不可以改变,值可以是任意数据类型。
例子,字典dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,2]}
①访问字典:
dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,5]}
value1=dics["小红"]
print(value1[2])
输出5
②增:
dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,5]}
dics["小米"]=520520
print(dics)
输出:dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,5],"小米":520520}
③改:
dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,5]}
dics["小张"]=156
print(dics)
输出:dics={"小张":156,"小黄":4562,"熊":2582,"小红":[0,1,5]}
④删:
删除某个键:
dics={"小张":1234,"小黄":4562,"熊":2582,"小红":[0,1,5]}
del dics["小张"]
print(dics)
输出dics={"小黄":4562,"熊":2582,"小红":[0,1,5]}
清除全部:dics.clear()
print(dics) 时,为空{}。
网友评论