Python的程序结构[2] -> 类/Class[0] -> 类的特殊属性
2024-08-24 11:06:53
类的特殊属性 / Special Property of Class
Python 中通过 class 进行类的定义,类可以实例化成实例并利用实例对方法进行调用。
类中还包含的一些共有的特殊属性。
特殊类属性 |
含义 |
__name__ |
类的名字(字符串) |
__doc__ |
类的文档字符串 |
__bases__ |
类的所有父类组成的元组 |
__dict__ |
类的属性组成的字典 |
__module__ |
类所属的模块 |
__class__ |
类对象的类型 |
class Foo():
"""
This is the text that can be called by __doc__
"""
def __init__(self):
self.foo = None def foo_method(self):
self.foom = True print('>>>', Foo.__name__)
print('>>>', Foo.__doc__)
print('>>>', Foo.__bases__)
print('>>>', Foo.__dict__)
print('>>>', Foo.__module__)
print('>>>', Foo.__class__)
上面的代码定义了一个 Foo 类,并对类的基本特殊属性依次进行调用,最后得到结果如下,
>>> Foo
>>>
This is the text that can be called by __doc__ >>> (<class 'object'>,)
>>> {'__dict__': <attribute '__dict__' of 'Foo' objects>, '__doc__': '\n This is the text that can be called by __doc__\n ', '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__init__': <function Foo.__init__ at 0x0301F930>, '__module__': '__main__', 'foo_method': <function Foo.foo_method at 0x0305C348>}
>>> __main__
>>> <class 'type'>
最新文章
- <;input type=";file"; id=";camera"; multiple=";multiple"; capture=";camera"; accept=";image/*";>; 上传图片,手机调用相册和摄像头
- 在HTML网页中设置弹出窗口的办法
- hibernate主键生成策略(转载)
- centos7 安装kvm, 并创建虚拟机
- linux操作系统的分类及解释
- 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug
- 对话(VC_Win32)
- C#对SQLite、Access数据库操作的封装,很好用的~
- 深入浅出低功耗蓝牙(BLE)协议栈
- java_lambda表达式
- org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;com.microsoft.sqlserver.jdbc.SQLServerDriver &#39;
- [Uva P11168] Airport
- Qt sprintf_s函数格式化字符串出错
- cgi调用linux系统命令
- How To Scan QRCode For UWP (3)
- 一个汇编的HelloWorld!
- c# update check
- qt——QFileDialog使用对话框选取本地文件
- CMS: DNN And Umbraco
- pip镜像源配置
热门文章
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目7
- Java EE - Servlet 小结
- 【Python-遇到的Error】AttributeError: &#39;str&#39; object has no attribute &#39;input_text&#39;
- Day2 Activity生命周期/启动模式/最佳实践
- 软工实践Alpha冲刺(8/10)
- static_cast AND dynamic_cast
- 【Android】实验3 颜色、字符串资源的使用【提交截止时间:2016.4.1】
- gulp入门1
- Json对象转json数组
- Python中的返回函数与闭包