Python是一種面向對象的編程語言,它的核心概念是類 。在Python中,類是創建對象的模板,它包含了一組屬性和方法 。當我們需要查看類的函數時,通常有以下幾種方法 。一、使用help函數
Python內置的help函數可以幫助我們查看類的函數 。我們可以使用help函數來獲取類的文檔字符串,文檔字符串包含了該類的所有方法和屬性的詳細介紹 。代碼如下:

```python
class MyClass:
def func1(self):
"""
This is func1
"""
pass
def func2(self):
"""
This is func2
"""
pass
help(MyClass)
```
運行上述代碼后,我們可以看到如下輸出:
```
class MyClass(builtins.object)
|Methods defined here:
|
|func1(self)
|This is func1
|
|func2(self)
|This is func2
|
|----------------------------------------------------------------------
|Data descriptors defined here:
|
|__dict__
|dictionary for instance variables (if defined)
|
|__weakref__
|list of weak references to the object (if defined)
|
|----------------------------------------------------------------------
|Data and other attributes defined here:
|
|__module__ = '__main__'
|Module name.
|
|----------------------------------------------------------------------
|Methods inherited from builtins.object:
|
|__delattr__(self, name, /)
|Implement delattr(self, name).
|
|__dir__(...)
|__dir__() -> list
|default dir() implementation
|
|__eq__(self, other, /)
|Return self==value.
|
|__format__(...)
|Default object formatter.
|
|__ge__(self, other, /)
|Return self>=value.
|
|__getattribute__(self, name, /)
|Return getattr(self, name).
|
|__gt__(self, other, /)
|Return self>value.
|
|__hash__(self, /)
|Return hash(self).
|
|__init__(self, /, *args, **kwargs)
|Initialize self.See help(type(self)) for accurate signature.
|
|__init_subclass__($self, /, *args, **kwargs)
|This method is called when a class is subclassed.
|
|__le__(self, other, /)
|Return self<=value.
|
|__lt__(self, other, /)
|Return self
|__ne__(self, other, /)
|Return self!=value.
|
|__new__(*args, **kwargs) from builtins.type
|Create and return a new object.See help(type) for accurate signature.
|
|__reduce__(...)
|Helper for pickle.
|
【python如何查看類的函數?】 |__reduce_ex__(...)
|Helper for pickle.
|
|__repr__(self, /)
|Return repr(self).
|
|__setattr__(self, name, value, /)
|Implement setattr(self, name, value).
|
|__sizeof__(...)
|__sizeof__() -> int
|size of object in memory, in bytes
|
|__str__(self, /)
|Return str(self).
|
|__subclasshook__(...)
|Abstract classes can override this to customize issubclass().
|
|----------------------------------------------------------------------
|Static methods inherited from builtins.object:
|
|__new__(*args, **kwargs) from builtins.type
|Create and return a new object.See help(type) for accurate signature.
|
|----------------------------------------------------------------------
|Data descriptors inherited from builtins.object:
|
|__class__
|type(object_or_name) -> the object's type
|
|__delattr__
|x.__delattr__('name')
猜你喜歡
- python中如何進行希爾排序?
- 吧椅如何選購?吧椅的清潔與保養
- 防盜窗的選購技巧-防盜窗如何清潔?
- 和田地毯如何清洗?和田地毯是什么?
- 指甲保養也是一門學問 如何處理指甲表面不光滑的情況
- 純銀飾品日常保養方法 如何正確處理發黑銀飾
- 衛生間有異味如何去除?水果去異味
- 浴缸應該如何清潔與保養
- 教你如何保養白色衣服
- python實現帶錯誤處理功能的遠程文件讀取方法
