当前位置:网站首页>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 .
边栏推荐
- Analysis of gas fee setting under eip1559
- Network security Kali penetration learning how to get started with web penetration how to scan based on nmap
- BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply
- 强基计划 数学相关书籍 推荐
- The simplicity of laravel
- 原生表格-滚动-合并功能
- 5. MVVM model
- Micro service knowledge sorting - three pieces of micro Service Technology
- About unregistered transfer login page
- Sword finger offer 30 Stack containing min function
猜你喜欢

Kubernetes cluster builds efk log collection platform

How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
![[effective Objective-C] - block and grand central distribution](/img/09/22b979b97ea13d649b4b904637b79f.jpg)
[effective Objective-C] - block and grand central distribution

Shortest path problem of graph theory (acwing template)

Chapter 1: find the algebraic sum of odd factors, find the same decimal sum s (D, n), simplify the same code decimal sum s (D, n), expand the same code decimal sum s (D, n)

2022 Xinjiang latest road transportation safety officer simulation examination questions and answers

BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply

2.3 other data types

Xctf attack and defense world crypto master advanced area olddriver

Network security Kali penetration learning how to get started with web penetration how to scan based on nmap
随机推荐
6. Data agent object Defineproperty method
7. Data broker presentation
IP address is such an important knowledge that it's useless to listen to a younger student?
The 29th day of force deduction (DP topic)
2.4 conversion of different data types
Basic command of IP address configuration ---ip V4
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
Geek Daily: the system of monitoring employees' turnover intention has been deeply convinced off the shelves; The meta universe app of wechat and QQ was actively removed from the shelves; IntelliJ pla
11-grom-v2-05-initialization
Day11 - my page, user information acquisition, modification and channel interface
Popularize the basics of IP routing
Battle drag method 1: moderately optimistic, build self-confidence (1)
February 14-20, 2022 (osgear source code debugging +ue4 video +ogremain source code transcription)
Global and Chinese market of cyanuric acid 2022-2028: Research Report on technology, participants, trends, market size and share
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles
LabVIEW training
Test changes in Devops mode -- learning and thinking
AST (Abstract Syntax Tree)
Global and Chinese markets for medical temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Oak-d raspberry pie cloud project [with detailed code]