日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python?munch包?/Munch()?的用法詳解_python

作者:馬鵬森 ? 更新時間: 2022-11-06 編程語言

?安裝:

pip install munch

定義字典的三種方式:?

from munch import Munch
# 字典的定義方式1:
dict_1 = {'Age':8, 'School':'RUNOOB'}
print(dict_1)
 
# 字典的定義方式2:
dict_2 = dict(Age = 8, School='RUNOOB')
print(dict_2)
 
# 字典的定義方式3:
dict_3 = Munch()
dict_3.Age = 15
dict_3.School = 'RUNOOB'
print(dict_3)

得到結果:?

{'Age': 8, 'School': 'RUNOOB'}
{'Age': 8, 'School': 'RUNOOB'}
Munch({'Age': 15, 'School': 'RUNOOB'})

使用Munch()實現增刪改

#增刪改
# 增
dict_3.Weight='80kg'
print(dict_3)
# 刪
del dict_3.Age
print(dict_3)
#改
dict_3.School="西安"
print(dict_3)

得到結果:?

Munch({'Age': 15, 'School': 'RUNOOB', 'Weight': '80kg'})
Munch({'School': 'RUNOOB', 'Weight': '80kg'})
Munch({'School': '西安', 'Weight': '80kg'})

原文鏈接:https://blog.csdn.net/weixin_43135178/article/details/126852828

欄目分類
最近更新