Python-dictionary and python dictionary
A dictionary is a key-value data type. You can use strokes and letters to View Details of the corresponding page.
Features:
1. dictionary is not required. (If the strings in the dictionary are printed by light, the sorting will not be arranged in order, because the dictionary has no lower mark .)
Basic Syntax:
Info = {
'Stu1101': "TengLan Wu ",
'Stu1102': "LongZe Luola ",
'Stu1103': "XiaoZe Maliya ",
}
Search
Print (info ['stu1101']) # exact search. If not, an error is returned.
Info. get ('stu1108') # equivalent to fuzzy search, return nunl
Print ('stu1103' in info) # Check whether the key has a user
Modify
Info ['stu1101'] = 'burwlands'
Add
Info ['stu1104'] = 'cangjingkong'
Delete
Info. pop ('stu1101 ')
Search for Creation
Info. setdefault ('stu1101', {'www .baidu.com ': [1, 2]}) # first check whether stu1101 value exists. If so, print the original one. If not, create the following one.
Conversion
Info. items () # changed to the list form
Loop
For I in info:
Print (I, info [I])
The items (), keys (), and values () of the Python dictionary return a list.
>>> Dict = {1: 2, 'A': 'B', 'Hello': 'World '}
>>> Dict. values () # return all value values
['B', 2, 'World']
>>> Dict. keys () # return all key values
['A', 1, 'Hello']
>>> Dict. items () # return all values
[('A', 'B'), (1, 2), ('hello', 'World')]