当前位置: 首页 > 图灵资讯 > 行业资讯> python中__dict__的实例属性存储

python中__dict__的实例属性存储

发布时间:2024-08-21 22:26:58

1、所有实例属性都存储在Python中_dict__字典中,这是通常的dict,实例属性的维护是从字典中获得和修正的,对开发者完全开放。

>>>e=Employee('IT','bobo')
>>>e.__dict__
{'department':'IT','name':'bobo'}
>>>type(e.__dict__)
dict
>>>e.nameise.__dict__['name']
True
>>>e.__dict__['department']='HR'
>>>e.department
'HR'

2、实例属性存储在字典中,因此可以随时方便地添加或删除字段:

>>>e.age=30#没有定义age属性
>>>e.age
30
>>>e.__dict__
{'department':'IT','name':'bobo','age':30}
>>>dele.age
>>>e.__dict__
{'department':'IT','name':'d'}

以上是python___dict__实例属性存储,希望对大家有所帮助。更多Python学习推荐:python教学

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09