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实现带错误处理功能的远程文件读取方法