色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python中有幫助函數(shù)嗎

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

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

中文說(shuō)明:不帶參數(shù)時(shí),返回當(dāng)前范圍內(nèi)的變量、方法和定義的類(lèi)型列表;帶參數(shù)時(shí),返回參數(shù)的屬性、方法列表。如果參數(shù)包含方法__dir__(),該方法將被調(diào)用。如果參數(shù)不包含__dir__(),該方法將最大限度地收集參數(shù)信息。

參數(shù)object: 對(duì)象、變量、類(lèi)型。

版本:該函數(shù)在python各個(gè)版本中都有,但是每個(gè)版本中顯示的屬性細(xì)節(jié)有所不同。使用時(shí)注意區(qū)別。

例如

>>>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.

代碼實(shí)例

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

知識(shí)點(diǎn)擴(kuò)展:

help()函數(shù)的作用

在使用python來(lái)編寫(xiě)代碼時(shí),會(huì)經(jīng)常使用python自帶函數(shù)或模塊,一些不常用的函數(shù)或是模塊的用途不是很清楚,這時(shí)候就需要用到help函數(shù)來(lái)查看幫助。

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

怎么使用help函數(shù)查看python模塊中函數(shù)的用法

help()括號(hào)內(nèi)填寫(xiě)參數(shù),操作方法很簡(jiǎn)單。例如:

>>> 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.

到此這篇關(guān)于python中有幫助函數(shù)嗎的文章就介紹到這了,更多相關(guān)python幫助函數(shù)詳解內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 成人a毛片久久免费播放 | 精品一区二区在线欧美日韩 | 日韩18在线观看 | 久久精品中文字幕不卡一二区 | 国产一区二区三区毛片 | 三级黄色在线 | 国产精品一久久香蕉国产线看 | 视频在线二区 | 亚洲gogo人体大胆西西安徽 | 免费一级欧美片在线观看 | 亚洲欧美第一 | 欧美怡红院高清在线 | 久久一区二区三区99 | av片免费大全在线观看不卡 | 免费视频精品一区二区三区 | 92自拍视频 | 亚洲视频在线观看视频 | 中文字幕在线视频网站 | 91久久国产露脸精品免费 | 国产成人午夜性a一级毛片 国产成人午夜性视频影院 国产成人香蕉久久久久 | 一级特色黄大片 | 久久99久久精品免费思思 | 国产精品19禁在线观看2021 | 精品区 | 欧美 亚洲 中文字幕 | 成人毛片免费在线观看 | 免费一级毛片视频 | 亚洲精品综合一区在线 | 精品欧美一区二区三区四区 | 国产精品手机在线 | 爱啪网亚洲第一福利网站 | 最近中文字幕精彩视频 | 欧美日韩视频一区二区三区 | 久久久久国产免费 | 国产高清一区二区 | 高清一本之道加勒比在线 | 中文字幕va一区二区三区 | 亚洲欧美日韩精品久久亚洲区色播 | 美女被免费网站在线软件 | 久久草在线视频 | 亚洲综合久久1区2区3区 |