如何详细解析Python中munch包的Munch()函数应用?

2026-04-30 15:141阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计267个文字,预计阅读时间需要2分钟。

如何详细解析Python中munch包的Munch()函数应用?

安装:使用pip安装munch库定义字典的三种方式:

1.from munch import Munch

2.Munch()

3.munch.Munch()

如何详细解析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() 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'})

到此这篇关于Pythonmunch包/Munch()的用法的文章就介绍到这了,更多相关Pythonmunch包内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!

本文共计267个文字,预计阅读时间需要2分钟。

如何详细解析Python中munch包的Munch()函数应用?

安装:使用pip安装munch库定义字典的三种方式:

1.from munch import Munch

2.Munch()

3.munch.Munch()

如何详细解析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() 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'})

到此这篇关于Pythonmunch包/Munch()的用法的文章就介绍到这了,更多相关Pythonmunch包内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!