python中的dir()函數
dir()函數不帶參數時,返回當前范圍內的變量、方法和定義的類型列表;帶參數時,返回參數的屬性、方法列表。如果參數包含方法__dir__(),該方法將被調用。如果參數不包含__dir__(),該方法將限度地收集參數信息。
dir語法:
dir([object])
參數說明
object--對象、變量、類型。
返回值
返回模塊的屬性列表。
以下實例展示了dir的使用方法:
>>>dir()#獲得當前模塊的屬性列表
['__builtins__','__doc__','__name__','__package__','arr','myslice']
>>>dir([])#查看列表的方法
['__add__','__class__','__contains__','__delattr__','__delitem__','__delslice__','__doc__','__eq__',
'__format__','__ge__','__getattribute__','__getitem__','__getslice__','__gt__','__hash__','__iadd__',
'__imul__','__init__','__iter__','__le__','__len__','__lt__','__mul__','__ne__','__new__','__reduce__',
'__reduce_ex__','__repr__','__reversed__','__rmul__','__setattr__','__setitem__','__setslice__','__sizeof__',
'__str__','__subclasshook__','append','count','extend','index','insert','pop','remove','reverse','sort']
>>>
以上內容為大家介紹了python培訓之dir函數是啥意思,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。