Python如何查看对象有哪些内容和属性
1、查看python对象的内容方法:
如下代码:
a=[1,2,3] print(type(a)) print(a)
执行结果是:
<class'list'> [1,2,3]
也就是说通过print(type(对象名))可以输出对象类型,print(对象名)可以输出对象的详细信息。
2、查看一个对象有哪些属性
使用dir命令,如
text="string" dir(text)
执行结果是:
['__add__','__class__','__contains__','__delattr__','__doc__','__eq__','__format__','__ge__','__getattribut e__','__getitem__','__getnewargs__','__getslice__','__gt__','__hash__','__init__','__le__','__len__','__lt __','__mod__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__rmod__','__rmul__', '__setattr__','__sizeof__','__str__','__subclasshook__','_formatter_field_name_split','_formatter_parser','ca pitalize','center','count','decode','encode','endswith','expandtabs','find','format','index','isalnum',' isalpha','isdigit','islower','isspace','istitle','isupper','join','ljust','lower','lstrip','partition',' replace','rfind','rindex','rjust','rpartition','rsplit','rstrip','split','splitlines','startswith','strip ','swapcase','title','translate','upper','zfill']原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容