python 查询类有几个方法
本文章使用相关数据
class MyPractise:
pass
查询类的所有方法
dir(类名) 或 dir(类名())
class MyPractise:
pass
dir(MyPractise)
dir(MyPractise())
查询类中非私有方法
方法不以下划线开头
[s for s in 类名 if str(s).startswith(‘‘)]
或[s for s in 类名() if str(s).startswith(’’)]
[s for s in MyPractise if str(s).startswith('_')]
[s for s in MyPractise() if str(s).startswith('_')]
本文聚焦Python中查询类方法的相关内容。介绍了查询类所有方法可使用dir(类名)或dir(类名()),还说明了查询类中非私有方法,即方法不以下划线开头,可通过特定列表推导式实现。
6万+

被折叠的 条评论
为什么被折叠?



