当前位置:网站首页>Basic knowledge of dictionaries and collections
Basic knowledge of dictionaries and collections
2022-07-03 20:18:00 【Programming is too difficult】
Catalog
Dictionary creation
A dictionary stores key value pairs
Format :info = {"":"","":""}
sign : Curly braces 、 Each key value pair is separated by a comma .
In the dictionary key Value cannot be modified , And only ,value You can modify .
Access to dictionaries
Not accessed by subscript , Instead, fill in the brackets directly key Value .
Access to nonexistent keys
Direct access to nonexistent keys will report an error
Can pass get Method to determine what to look for key Not in the dictionary , If not , Default return None.
You can also set the value returned when it cannot be found .
Operation of the dictionary
increase
Set a dictionary object directly , Assign a value to it .
Delete
Use del Method to delete an object , Will delete the whole object , When using this object again , The system will report an error saying that this object has not been defined .
You can also delete the entire dictionary , All dictionary data can be output without brackets after the dictionary name .
Empty
use clear Method , Clear all the data in the dictionary, but the dictionary still exists .
modify
You can directly access and modify it .
lookup
When printing out , You can choose to output all key、 Output all value、 Output all key value pairs . But the output is followed by a list of all these values .
If you need to continue to visit the content inside , You can traverse the list
When traversing key value pairs ,for A loop can assign multiple variables at a time
Because it is stored in the list , If you need to operate the subscript of the list , You can use enumeration functions enumerate().
aggregate SET
Only... Is stored in the collection key Do not store value, And key Is the only one. , If there is duplication , The assembly will automatically de weight , Just one .
list 、 Tuples 、 Dictionaries 、 The difference between sets
Lists and tuples are ordered , Can be accessed by subscript .
Dictionaries and collections are out of order , Access by writing the variable name in brackets .
The values in the list can be changed .
Values in tuples cannot be changed .
In the dictionary key The value cannot be changed ,value You can change .
In the collection key It can be changed , And not repeated .
边栏推荐
- Micro service knowledge sorting - cache technology
- Part 27 supplement (27) buttons of QML basic elements
- Explore the internal mechanism of modern browsers (I) (original translation)
- Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue
- Global and Chinese market of liquid antifreeze 2022-2028: Research Report on technology, participants, trends, market size and share
- Professional interpretation | how to become an SQL developer
- Global and Chinese market of cyanuric acid 2022-2028: Research Report on technology, participants, trends, market size and share
- The simplicity of laravel
- Global and Chinese markets of cast iron diaphragm valves 2022-2028: Research Report on technology, participants, trends, market size and share
- Teach you how to quickly recover data by deleting recycle bin files by mistake
猜你喜欢
Wechat applet quick start (including NPM package use and mobx status management)
Virtual machine installation deepin system
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles
LabVIEW training
Phpstudy set LAN access
Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro
Use of aggregate functions
[effective Objective-C] - block and grand central distribution
Battle drag method 1: moderately optimistic, build self-confidence (1)
Shortest path problem of graph theory (acwing template)
随机推荐
Find a line in a file and remove it
Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!
Example of peanut shell inner net penetration
2166. Design bit set
强基计划 数学相关书籍 推荐
FAQs for datawhale learning!
MySQL dump - exclude some table data - MySQL dump - exclude some table data
AcWing 1460. Where am i?
How to set the system volume programmatically- How to programmatically set the system volume?
PR notes:
Global and Chinese market of micro positioning technology 2022-2028: Research Report on technology, participants, trends, market size and share
Introduction to golang garbage collection
[raid] [simple DP] mine excavation
Xctf attack and defense world crypto advanced area best_ rsa
Micro service knowledge sorting - three pieces of micro Service Technology
Phpexcel import export
Phpstudy set LAN access
Pat grade B 1009 is ironic (20 points)
How to improve data security by renting servers in Hong Kong
Battle drag method 1: moderately optimistic, build self-confidence (1)