Dictionary type:
# msg_dic = {
# ' Apple ': 10,
# ' Tesla ': 100000,
# ' Mac ': 3000,
# ' Lenovo ': 30000,
# ' chicken ': 10,
# }
# take only the value of key
# for K in Msg_dic:
# print (K,msg_dic[k])
# for K in Msg_dic.keys ():
# print (K,msg_dic[k])
# only values of value are taken
# for V in Msg_dic.values ():
# print (v)
# The value of #同时取key, value
# for K,v in Msg_dic.items ():
# Print (K,V)
# for loop fetch K
# info={' A ': 1, ' B ': 2, ' C ': 3}
# for X in info:
# # Print (Info[x])
# Print (x)
# Build a dictionary
# d=dict (a=1,b=2,c=3)
# print (d)
#可以修改, delete, and front and back ID unchanged
# info={' A ': 1, ' B ': 2, ' C ': 3}
# Print (Info,id (info))
# info[' A ']=3
# Print (Info,id (info))
# del info[' a '] Delete method one
# Print (info)
# info.pop (' B ') Delete method two
# Print (info)
# print (Info) Delete method Three: Random delete
# Info.popitem ()
# Print (info)
Ganso Type:
Purpose: Ganso is an immutable list
can have multiple values, but multiple values only need to be taken, without the need to change
Way:
Name= (' Zhangsan ', ' Lisi ', ' Wangwu ', ' Zhaoliu ')
How to define:
separated by commas within (), can hold any type of value
Emphasis: When there is only one element in the progenitor, it is important to remember to add a comma if there is only one, and it is of type str type
x= (' Yangzhizong ')
Print (type (x)) >>> output result is string type
Name= (' Zhangsan ', ' Lisi ', ' Wangwu ', ' AA ', ' Zhaoliu ', ' AA ', ' Zhangsan ')
# Take value
# print (name[0])
# slices, fetch 1, 2 strings
# print (Name[1:3])
# #长度
# print (len (name))
# Number of occurrences of an element in the Count statistics dictionary
# info=name.count (' AA ')
# Print (info)
#index在一定范围内, find the index position for the element
# info=name.index (' AA ', 1,4)
# Print (info)
‘
Python dictionary type,