当前位置:网站首页>Use dictionary
Use dictionary
2022-06-24 15:16:00 【User 8442333】
Dictionary is another variable container model , Similar to the dictionary we use in our life , It can store any type of object , And list 、 The difference between the sets is , Each element of the dictionary consists of a key and a value “ Key value pair ”, Keys and values are separated by colons . The following code shows how to define and use a dictionary .
def main():
scores = {' Luo Hao ': 95, ' Bai Yuanfang ': 78, ' Judge dee ': 82}
# The corresponding value in the dictionary can be obtained through the key
print(scores[' Luo Hao '])
print(scores[' Judge dee '])
# Traverse the dictionary ( Traversal is actually the key through the key to get the corresponding value )
for elem in scores:
print('%s\t--->\t%d' % (elem, scores[elem]))
# Update the elements in the dictionary
scores[' Bai Yuanfang '] = 65
scores[' Wang Lang, Zhuge '] = 71
scores.update( cold noodles =67, Fang Qihe =85)
print(scores)
if ' Wu zetian ' in scores:
print(scores[' Wu zetian '])
print(scores.get(' Wu zetian '))
# get Method also obtains the corresponding value through the key, but the default value can be set
print(scores.get(' Wu zetian ', 60))
# Delete elements from Dictionary
print(scores.popitem())
print(scores.popitem())
print(scores.pop(' Luo Hao ', 100))
# Empty dictionary
scores.clear()
print(scores)
if __name__ == '__main__':
main()边栏推荐
- postgresql之词法分析简介
- Analysis of similarities and differences between redis and memcached in cache use
- Method after charging the idea plug-in material theme UI
- update+catroot+c000021a+critical service failed+drivers+intelide+viaide+000000f
- laravel 8 实现Auth登录
- Keras deep learning practice (11) -- visual neural network middle layer output
- openinstall携手书链:助力渠道数据分析,共创书联网时代
- R language plot visualization: the visualization model creates a grid in the classification contour (contour) and meshgrid of the entire data space, in which the distance between each point is determi
- Golang实现Biginteger大数计算
- Qunhui synchronizes with alicloud OSS
猜你喜欢

Common sense knowledge points

Successfully solved: selenium common. exceptions. SessionNotCreatedException: Message: session not created: This versi

From pair to unordered_ Map, theory +leetcode topic practice

Keyword of ES mapping; Term query add keyword query; Change mapping keyword type

MySQL log management, backup and recovery

Qunhui synchronizes with alicloud OSS

测试 H5 和小程序的区别,你真的知道吗?

Port conflict handling method for tongweb

Bert-whitening 向量降维及使用

API data interface for announcement of Hong Kong listed companies
随机推荐
How do individuals open accounts for stock speculation? Is it safe to open accounts for stock speculation
Design of vga/lcd display controller system based on FPGA (Part 2)
Design of vga/lcd display controller system based on FPGA (Part 1)
How to achieve long-term development of voice social source code?
Keyword of ES mapping; Term query add keyword query; Change mapping keyword type
Go language - use of goroutine coroutine
入行 4 年,跳槽 2 次,我摸透了软件测试这一行
Is it safe to open a stock account by mobile phone
[bitbear story collection] June MVP hero story | technology practice collision realm thinking
Carry forward the fine style of continuous operation and go all out to ensure the safety of Beijiang Levee
Bitmap of redis data structure
A simple and powerful developer toolkit box3 cc
postgresql之List
Ethical considerations
The security market has entered a trillion era, and the security B2B online mall system has been accurately connected to deepen the enterprise development path
From pair to unordered_ Map, theory +leetcode topic practice
在宇宙的眼眸下,如何正确地关心东数西算?
Actual combat | a tortuous fishing counteraction
MySQL log management, backup and recovery
兴业证券靠谱吗?开证券账户安全吗?