網(wǎng)站首頁 編程語言 正文
?安裝:
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)
得到結(jié)果:?
{'Age': 8, 'School': 'RUNOOB'}
{'Age': 8, 'School': 'RUNOOB'}
Munch({'Age': 15, 'School': 'RUNOOB'})
使用Munch()實現(xiàn)增刪改
#增刪改
# 增
dict_3.Weight='80kg'
print(dict_3)
# 刪
del dict_3.Age
print(dict_3)
#改
dict_3.School="西安"
print(dict_3)
得到結(jié)果:?
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
相關(guān)推薦
- 2022-10-03 Pandas中inf值替換的方法_python
- 2022-09-25 nginx平滑升級、nginx支持的kill信號
- 2022-12-27 python利用logging模塊實現(xiàn)根據(jù)日志級別打印不同顏色日志的代碼案例_python
- 2022-09-25 Linux安裝Nginx詳細(xì)教程
- 2023-03-27 拓?fù)渑判騊ython實現(xiàn)的過程_python
- 2022-04-16 pycharm三個有引號不能自動生成函數(shù)注釋的問題_python
- 2023-02-18 React錯誤的習(xí)慣用法分析詳解_React
- 2022-06-12 Flutter仿微信通訊錄實現(xiàn)自定義導(dǎo)航條的示例代碼_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支