当前位置:首页 > 云计算 > 正文内容

Python如何查看对象有哪些内容和属性

2022-05-04 03:21:51云计算1

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']

更多技术请关注Python视频教程。

本网站文章仅供交流学习 ,不作为商用, 版权归属原作者,部分文章推送时未能及时与原作者取得联系,若来源标注错误或侵犯到您的权益烦请告知,我们将立即删除.

本文链接:https://www.xibujisuan.cn/13930.html

标签: Python