亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python中有幫助函數嗎

瀏覽:2日期:2022-07-20 10:46:39

python中的dir()函數是一個非常重要的函數,它可以幫助我們查看函數的功能和特性。

中文說明:不帶參數時,返回當前范圍內的變量、方法和定義的類型列表;帶參數時,返回參數的屬性、方法列表。如果參數包含方法__dir__(),該方法將被調用。如果參數不包含__dir__(),該方法將最大限度地收集參數信息。

參數object: 對象、變量、類型。

版本:該函數在python各個版本中都有,但是每個版本中顯示的屬性細節有所不同。使用時注意區別。

例如

>>>import struct>>>dir() # show the names in the module namespace[’__builtins__’,’__doc__’,’__name__’,’struct’]>>>dir(struct) # show the names in the struct module[’Struct’,’__builtins__’,’__doc__’,’__file__’,’__name__’, ’__package__’,’_clearcache’,’calcsize’,’error’,’pack’,’pack_into’, ’unpack’,’unpack_from’]>>>class Shape(object): def __dir__(self): return [’area’,’perimeter’,’location’]>>> s= Shape()>>>dir(s)

[’area’, ’perimeter’, ’location’]Note Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.

代碼實例

>>>dir()[’__builtins__’,’__doc__’,’__name__’,’__package__’]>>>import struct>>>dir()[’__builtins__’,’__doc__’,’__name__’,’__package__’,’struct’]>>>dir(struct)[’Struct’,’__builtins__’,’__doc__’,’__file__’,’__name__’,’__package__’,’_clearcache’,’calcsize’,’error’,’pack’,’pack_into’,’unpack’,’unpack_from’]>>>class Person(object):... def __dir__(self):... return ['name','age','country']...>>>dir(Person)[’__class__’,’__delattr__’,’__dict__’,’__dir__’,’__doc__’,’__format__’,’__getattribute__’,’__hash__’,’__init__’,’__module__’,’__new__’,’__reduce__’,’__reduce_ex__’,’__repr__’,’__setattr__’,’__sizeof__’,’__str__’,’__subclasshook__’,’__weakref__’]>>> tom= Person()>>>dir(tom)[’age’,’country’,’name’]

知識點擴展:

help()函數的作用

在使用python來編寫代碼時,會經常使用python自帶函數或模塊,一些不常用的函數或是模塊的用途不是很清楚,這時候就需要用到help函數來查看幫助。

這里要注意下,help()函數是查看函數或模塊用途的詳細說明,而dir()函數是查看函數或模塊內的操作方法都有什么,輸出的是方法列表。

怎么使用help函數查看python模塊中函數的用法

help()括號內填寫參數,操作方法很簡單。例如:

>>> help(’dir’)Help on built-in function dir in module builtins:dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module’s attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class’s attributes, and recursively the attributes of its class’s base classes.

到此這篇關于python中有幫助函數嗎的文章就介紹到這了,更多相關python幫助函數詳解內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 欧美一区二区三区视频 | 日本无翼乌邪恶大全彩h邪恶师 | 亚洲国产中文字幕 | 宅男噜噜噜一区二区三区 | 国产黄拍 | 亚洲欧美日韩一区超高清 | 免费超爽大片黄 | 亚洲欧美日韩在线精品2021 | 黄色大全免费看 | 成人午夜在线观看国产 | 久久草在线免费 | 欧美一级特级毛片 | 免费视频爱爱太爽在线观看 | 男女又黄又刺激黄a大片桃色 | 综合网在线 | 亚洲欧美视频 | 国产日本在线 | 全国精品影院 | 久久亚洲精品中文字幕亚瑟 | 国产伦精品一区二区三区网站 | 亚洲国产精品久久久久秋霞小 | 欧美一区二区久久精品 | 久久青青草原精品老司机 | 久久视频在线播放视频99re6 | 成人亚洲国产综合精品91 | 99热在线观看精品 | 国产福利在线观看精品 | 亚洲国产高清在线精品一区 | 劲爆欧美色欧美 | 成人av手机在线观看 | 一级毛片一级毛片一级毛片 | 日本毛片在线观看 | 欧美性视频一区二区三区 | 999精品影视在线观看 | 小泽玛利亚一区二区 | 成人男女网18免费软件大全 | 午夜在线亚洲 | 在线观看亚洲精品专区 | 亚洲午夜视频在线观看 | 中文字幕亚洲国产 | 亚洲品质自拍视频 |