Dictionary Basic Rules and Introduction

dict

1. Key-value pair

2. The value of the dictionary can be any value, such as a list, a tuple, a dictionary, etc.

3. Lists and dictionaries cannot be used as the keys of dictionaries, because lists are dynamic and modifiable, while tuples can

4. The dictionary is unordered. Check whether the order of each output is the same by printing multiple times.

5. The index is to find the value through the key, and cannot be searched through slices, because it is unordered

info = {11:45,45:54,45:45,}
v = info [11 ]
 print (v)

45

6. Can be deleted

info = {11:45,45:54,45:45 ,}
 del info[11 ]
 print (info)

7. The for loop on the dictionary is the default loop key, for item in info.values() gets the value loop for k,v in info.items() loops the key-value pair

8. If the key is repeated, there can only be one, and the other value will be displayed as another value, such as 1 or 0

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325260257&siteId=291194637
Recommended