当前位置:网站首页>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
- Micro service knowledge sorting - asynchronous communication technology
- Initialization and instantiation
- [raid] [simple DP] mine excavation
- About unregistered transfer login page
- Plan for the first half of 2022 -- pass the PMP Exam
- Explore the internal mechanism of modern browsers (I) (original translation)
- Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
- Find a line in a file and remove it
- FPGA 学习笔记:Vivado 2019.1 工程创建
猜你喜欢
Promethus
BOC protected phenylalanine zinc porphyrin (Zn · TAPP Phe BOC) / iron porphyrin (Fe · TAPP Phe BOC) / nickel porphyrin (Ni · TAPP Phe BOC) / manganese porphyrin (Mn · TAPP Phe BOC) Qiyue Keke
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
Xctf attack and defense world crypto advanced area best_ rsa
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
Introduction to golang garbage collection
2.2 integer
MPLS configuration
2.1 use of variables
2.5 conversion of different data types (2)
随机推荐
Golang type assertion and conversion (and strconv package)
Rd file name conflict when extending a S4 method of some other package
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles
1.5 learn to find mistakes first
Initialization and instantiation
Professional interpretation | how to become an SQL developer
Virtual machine installation deepin system
Use of CMD command
BOC protected alanine porphyrin compound TAPP ala BOC BOC BOC protected phenylalanine porphyrin compound TAPP Phe BOC Qi Yue supply
Global and Chinese markets of cast iron diaphragm valves 2022-2028: Research Report on technology, participants, trends, market size and share
Day11 - my page, user information acquisition, modification and channel interface
Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
Microservice knowledge sorting - search technology and automatic deployment technology
Pat grade B 1009 is ironic (20 points)
Wechat applet quick start (including NPM package use and mobx status management)
Don't be afraid of no foundation. Zero foundation doesn't need any technology to reinstall the computer system
Global and Chinese markets for medical temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Day6 merge two ordered arrays
2.3 other data types
Popularize the basics of IP routing