类的特殊属性 / 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'>

最新文章

  1. &lt;input type=&quot;file&quot; id=&quot;camera&quot; multiple=&quot;multiple&quot; capture=&quot;camera&quot; accept=&quot;image/*&quot;&gt; 上传图片,手机调用相册和摄像头
  2. 在HTML网页中设置弹出窗口的办法
  3. hibernate主键生成策略(转载)
  4. centos7 安装kvm, 并创建虚拟机
  5. linux操作系统的分类及解释
  6. 记一个python+sqlalchemy+tornado的一个高并发下,产生重复记录的bug
  7. 对话(VC_Win32)
  8. C#对SQLite、Access数据库操作的封装,很好用的~
  9. 深入浅出低功耗蓝牙(BLE)协议栈
  10. java_lambda表达式
  11. org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;com.microsoft.sqlserver.jdbc.SQLServerDriver &#39;
  12. [Uva P11168] Airport
  13. Qt sprintf_s函数格式化字符串出错
  14. cgi调用linux系统命令
  15. How To Scan QRCode For UWP (3)
  16. 一个汇编的HelloWorld!
  17. c# update check
  18. qt——QFileDialog使用对话框选取本地文件
  19. CMS: DNN And Umbraco
  20. pip镜像源配置

热门文章

  1. 《Cracking the Coding Interview》——第8章:面向对象设计——题目7
  2. Java EE - Servlet 小结
  3. 【Python-遇到的Error】AttributeError: &#39;str&#39; object has no attribute &#39;input_text&#39;
  4. Day2 Activity生命周期/启动模式/最佳实践
  5. 软工实践Alpha冲刺(8/10)
  6. static_cast AND dynamic_cast
  7. 【Android】实验3 颜色、字符串资源的使用【提交截止时间:2016.4.1】
  8. gulp入门1
  9. Json对象转json数组
  10. Python中的返回函数与闭包