__setitem__
时间: 2023-08-26 14:14:59 浏览: 122
__setitem__是一个魔法函数,用于在自定义类中实现类似于给字典设置键值对的功能。当一个类实现了__setitem__函数,它的对象就可以使用类似于字典的方式设置键值对。这样,我们可以通过s["name"]和s["age"]来获取设置的值。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python----魔法函数__getitem__/__setitem__/__delitem__的用法](https://blog.csdn.net/redrose2100/article/details/118097251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [一分钟学会python的__setitem__方法](https://blog.csdn.net/Norsaa/article/details/105565431)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文