国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

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

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

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

參數(shù)object: 對象、變量、類型。

版本:該函數(shù)在python各個版本中都有,但是每個版本中顯示的屬性細節(jié)有所不同。使用時注意區(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.

代碼實例

>>>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()函數(shù)的作用

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

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

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

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

>>> 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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产免费一区不卡在线 | 亚洲a人| 国产永久免费高清动作片www | 免费在线看黄网址 | 九九这里只精品视在线99 | 国产精品久久久久久久久久久久久久 | 亚洲精品一区二区综合 | 日韩欧美在线精品 | 国产精品久久国产三级国不卡顿 | 欧美成人看片一区二区三区尤物 | a毛片免费 | 一级片欧美 | 一区二区在线欧美日韩中文 | 一级毛片子 | 国产欧美一区二区三区沐欲 | 26uuu天天夜夜综合 | 欧美高h视频 | 国产精选在线 | 99国产精品欧美久久久久久影院 | 国产欧美日韩亚洲精品区2345 | 国产精品国内免费一区二区三区 | 色综合久久一本首久久 | 国产91一区二这在线播放 | 中日韩一区二区三区 | 日韩中文字幕在线免费观看 | 免费区一级欧美毛片 | a视频免费| 免费国产成人高清在线看软件 | 精品国产三级 | 亚洲国产日韩欧美综合久久 | 香港aa三级久久三级老师 | 男人的天堂在线观看免费 | 亚洲综合色在线观看 | 国内精品久久久久久 | 精品性久久 | 国产4tube在线播放 | 欧美一级特黄aa大片视频 | 91久久国产综合精品女同国语 | 久久精品国产99国产精品亚洲 | 日韩一级欧美一级毛片在 | 欧美在线成人免费国产 |