新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python如何查看對象有哪些內(nèi)容和屬性
python如何查看對象有哪些內(nèi)容和屬性

1、查看python對象的內(nèi)容方法:
如下代碼:
a = [1,2,3] print(type(a)) print(a)
執(zhí)行結(jié)果是:
[1, 2, 3]
也就是說通過print(type(對象名))可以輸出對象類型,print(對象名)可以輸出對象的詳細(xì)信息。
2、查看一個對象有哪些屬性
使用dir命令,如
text="string" dir(text)
執(zhí)行結(jié)果是:
['__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']
更多技術(shù)請關(guān)注Python視頻教程。
分享題目:創(chuàng)新互聯(lián)Python教程:Python如何查看對象有哪些內(nèi)容和屬性
URL網(wǎng)址:http://fisionsoft.com.cn/article/dhdecco.html


咨詢
建站咨詢
