Python面向对象特殊属性及方法解析
作者:Xujie_0528 时间:2022-05-19 15:16:06
特殊属性
Python中对象包括很多双下划綫开始和结束的属性,这些特殊属性,有特殊用法。
特殊方法 | 含义 |
obj.__dict__ | 对象的属性字典 |
obj.__class__ | 对象所处的类 |
class.__bases__ | 类的基本元组(多继承) |
class.__base__ | 类的基类 |
class.__mro__ | 类层次结构 |
class.__subclasses__() | 子类列表 |
代码如下
class A:
pass
class B:
pass
class C(A,B):
def __init__(self,nn):
self.nn = nn
def cc(self):
print('cc')
c = C(3)
print(dir(c))
print(c.__dict__)
print(c.__class__)
print(C.__bases__)
print(C.mro())
print(A.__subclasses__())
结果
来源:https://www.cnblogs.com/xujie-0528/p/13671754.html
标签:Python,特殊,属性,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Python matplotlib库绘制箱线图
2021-09-04 22:23:24
![](https://img.aspxhome.com/file/2023/4/109444_0s.png)
Python调用高德API实现批量地址转经纬度并写入表格的功能
2023-12-26 03:22:20
![](https://img.aspxhome.com/file/2023/3/101673_0s.png)
Bootstrap 模态对话框只加载一次 remote 数据的完美解决办法
2023-08-06 15:58:18
![](https://img.aspxhome.com/file/2023/0/55970_0s.png)
Oracle数据库集复制方法浅议
2023-07-16 16:33:49
Python的dict字典结构操作方法学习笔记
2022-10-27 10:56:21
模拟下拉菜单[兼容IE系列以及火狐]
2009-12-13 10:23:00
![](https://img.aspxhome.com/file/UploadPic/200912/13/menu-37s.gif)
pycharm实现print输出保存到txt文件
2023-05-09 22:14:20
![](https://img.aspxhome.com/file/2023/4/99104_0s.jpg)
挑战! 纯Javascript 重现经典网游! <魔力宝贝>
2008-10-04 10:37:00
![](https://img.aspxhome.com/file/UploadPic/200810/4/2008104104524850s.jpg)
网页设计求职全攻略
2008-07-09 18:56:00
CentOS环境下安装Redis3.0及phpredis扩展测试示例
2023-11-21 18:20:05
![](https://img.aspxhome.com/file/2023/1/110141_0s.png)
纯CSS Tooltips提示
2008-10-18 16:01:00
Python学习笔记之变量与转义符
2022-12-20 23:21:18
![](https://img.aspxhome.com/file/2023/9/72769_0s.png)
Flask使用SQLAlchemy实现持久化数据
2023-02-23 07:47:19
在Python中处理日期和时间的基本知识点整理汇总
2021-05-13 07:12:14
![](https://img.aspxhome.com/file/2023/9/89079_0s.jpg)
专家教你安装 MySQL的与MySQL GUI Tools
2012-01-29 17:59:05
CSS压缩:技巧与工具
2009-12-11 18:26:00
![](https://img.aspxhome.com/file/UploadPic/200912/11/shorthand-39s.jpg)
python数字图像处理之对比度与亮度调整示例
2021-02-13 19:33:19
![](https://img.aspxhome.com/file/2023/4/70764_0s.png)
python GUI库图形界面开发之PyQt5窗口控件QWidget详细使用方法
2023-05-25 23:48:29
![](https://img.aspxhome.com/file/2023/5/100845_0s.png)
Python创建简单的神经网络实例讲解
2021-12-02 05:38:41
![](https://img.aspxhome.com/file/2023/2/72762_0s.png)
详解django自定义中间件处理
2023-09-30 08:19:12