当前位置:网站首页>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 .
边栏推荐
- The simplicity of laravel
- Titles can only be retrieved in PHP via curl - header only retrieval in PHP via curl
- Nerfplusplus parameter format sorting
- Bright purple crystal meso tetra (4-aminophenyl) porphyrin tapp/tapppt/tappco/tappcd/tappzn/tapppd/tappcu/tappni/tappfe/tappmn metal complex - supplied by Qiyue
- Day6 merge two ordered arrays
- 2.3 other data types
- Print linked list from end to end
- 4. Data splitting of Flink real-time project
- 5- (4-nitrophenyl) - 10,15,20-triphenylporphyrin ntpph2/ntppzn/ntppmn/ntppfe/ntppni/ntppcu/ntppcd/ntppco and other metal complexes
- Machine learning support vector machine SVM
猜你喜欢

Teach you how to quickly recover data by deleting recycle bin files by mistake

How to improve data security by renting servers in Hong Kong
![[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University](/img/95/5baf5c8bedb00e67394a6c0a8234ff.png)
[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University

JMeter plug-in installation

LabVIEW training

Exercises of function recursion

FAQs for datawhale learning!

It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET

2.2 integer

Machine learning support vector machine SVM
随机推荐
Commands related to files and directories
LabVIEW training
Assign the CMD command execution result to a variable
[Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
The 15 year old interviewer will teach you four unique skills that you must pass the interview
About unregistered transfer login page
Make a simple text logo with DW
2.6 formula calculation
unittest框架基本使用
MySQL dump - exclude some table data - MySQL dump - exclude some table data
Cap and base theory
Fingerprint password lock based on Hal Library
Unittest framework is basically used
Upgrade PIP and install Libraries
IP address is such an important knowledge that it's useless to listen to a younger student?
4. Data splitting of Flink real-time project
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
[effective Objective-C] - block and grand central distribution
unittest框架基本使用
Microservice knowledge sorting - search technology and automatic deployment technology