当前位置:网站首页>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 .
边栏推荐
- 11-grom-v2-04-advanced query
- 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
- 5. MVVM model
- AST (Abstract Syntax Tree)
- An old programmer gave it to college students
- 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)
- 2.1 use of variables
- 【leetcode】1027. Longest arithmetic sequence (dynamic programming)
- JMeter plug-in installation
- Don't be afraid of no foundation. Zero foundation doesn't need any technology to reinstall the computer system
猜你喜欢
AcWing 1460. Where am i?
JMeter plug-in installation
原生表格-滚动-合并功能
The 29th day of force deduction (DP topic)
2.6 formula calculation
thrift go
Exercises of function recursion
Part 28 supplement (XXVIII) busyindicator (waiting for elements)
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
[effective Objective-C] - block and grand central distribution
随机推荐
Global and Chinese market of high purity copper foil 2022-2028: Research Report on technology, participants, trends, market size and share
Wargames study notes -- Leviathan
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)
Wechat applet quick start (including NPM package use and mobx status management)
Global and Chinese market of cyanuric acid 2022-2028: Research Report on technology, participants, trends, market size and share
Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
Task of gradle learning
Test access criteria
5. MVVM model
Exercises of function recursion
Native table - scroll - merge function
Global and Chinese market of micro positioning technology 2022-2028: Research Report on technology, participants, trends, market size and share
Analysis of gas fee setting under eip1559
Global and Chinese market of full authority digital engine control (FADEC) 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of polyimide tubes for electronics 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL learning notes - single table query
6. Data agent object Defineproperty method
Kubernetes cluster builds efk log collection platform
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
Battle drag method 1: moderately optimistic, build self-confidence (1)