Python munch包 /Munch() 的用法详解 安装: 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
安装:
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包内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
本文标题为:Python munch包 /Munch() 的用法详解


基础教程推荐
- Python爬虫爬取属于自己的地铁线路图 2023-08-05
- 使用Pycharm创建一个Django项目的超详细图文教程 2022-09-02
- windows下面使用多版本Python安装指定版本的虚拟环境 2023-09-04
- linux 安装 python3 2023-09-03
- Python+OpenCV实战之实现文档扫描 2022-10-20
- 创建python虚拟环境(在ubuntu16.04中) 2023-09-04
- 远程和Ubuntu服务器进行Socket通信,使用python和C#(准备篇) 2023-09-05
- MySQL数据优化-多层索引 2023-08-11
- python验证多组数据之间有无显著差异 2023-08-08
- 云服务器Ubuntu更改默认python版本 2023-09-03