当前位置: 首页 > 图灵资讯 > 行业资讯> Python如何查看对象有哪些内容和属性

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

发布时间:2026-06-07 21:59:45

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视频教程的更多信息。

相关文章

如何切换到Python2.7

如何切换到Python2.7

2026-06-26
Python字典如何换行

Python字典如何换行

2026-06-26
Python中怎么新建文件夹

Python中怎么新建文件夹

2026-06-26
Python中区分字符与字符串吗

Python中区分字符与字符串吗

2026-06-26
Python如何查看对象有哪些内容和属性

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

2026-06-07
Python测试有什么用途

Python测试有什么用途

2026-06-07