創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!
小編給大家分享一下python中有沒有幫助函數(shù),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
python中的dir()函數(shù)是一個非常重要的函數(shù),它可以幫助我們查看函數(shù)的功能和特性。
中文說明:不帶參數(shù)時,返回當前范圍內的變量、方法和定義的類型列表;帶參數(shù)時,返回參數(shù)的屬性、方法列表。如果參數(shù)包含方法__dir__(),該方法將被調用。如果參數(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.
代碼實例(更多學習內容,請點擊創(chuàng)新互聯(lián))
>>>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']
以上是python中有沒有幫助函數(shù)的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)-成都網(wǎng)站建設公司行業(yè)資訊頻道!
當前標題:python中有沒有幫助函數(shù)-創(chuàng)新互聯(lián)
URL分享:http://aaarwkj.com/article22/dsjgcc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿建站、網(wǎng)站內鏈、網(wǎng)站維護、搜索引擎優(yōu)化、品牌網(wǎng)站制作、電子商務
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)