安装: 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) # 字
安装:
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'})
到此这篇关于Python munch包 /Munch() 的用法的文章就介绍到这了,更多相关Python munch包内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!