mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6
27 字
1 分钟
python的自省
2026-03-12

python自省#

简单说自省就是python能够在程序运行时知道对象的的类型

#自省就是python能够在程序运行时知道对象的的类型
a=[1,2,3]
print(type(a))
print(dir(a))#dir用于显示出一个对象所有的属性,方法,变量!返回列表
print(isinstance(a,list))#用于检测a是不是list的子类
#输出
<class 'list'>
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
True
分享

如果这篇文章对你有帮助,欢迎分享给更多人!

python的自省
https://mizuki.mysqil.com/posts/zixing/
作者
神秘大胖狗
发布于
2026-03-12
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

封面
Sample Song
Sample Artist
封面
Sample Song
Sample Artist
0:00 / 0:00