Python Note
Object and Class
constructor
物件建立時,物件本身所執行的函式
example:
class myClass: def __init__(self): print self
result: >>> myClass
<class __main__.myClass at 0x011ED690>
內建屬性
- classname.__dict__: 類別內的屬性以辭典集物件方式儲存
example:
class myClass: "A simple example class" a=123
result: >>> myClass.__dict__
{'a': 123, '__module__': '__main__', '__doc__': 'A simple example class'}
- class.__doc__ : __doc__屬性傳回此類別的文件字串
- class.__name__ : __name__屬性傳回此類別的名稱
- class.__module__ : __module__屬性傳包含回此類別的文件字串
- class.__bases__: __bases__屬性是一個tuple物件,傳回此類別的基底類別名稱
example1:
class myClass: "A simple example class" a=123
result: >>> myClass.__bases__
()
example2:
class myClass: "A simple example class" a=123 class a(myClass): "A Derived Class" b=321
result: >>> a.__bases__
(<class __main__.myClass at 0x011ED6C0>,)
Last modified 15 years ago
Last modified on Oct 30, 2009, 10:41:12 AM