最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年06月19日 16:02:36   作者:silencement  
在本篇文章里小編給大家分享的是一篇關(guān)于python幫助函數(shù)詳解內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。

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

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

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

版本:該函數(shù)在python各個版本中都有,但是每個版本中顯示的屬性細(xì)節(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']

知識點擴(kuò)展:

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

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

這里要注意下,help()函數(shù)是查看函數(shù)或模塊用途的詳細(xì)說明,而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 attribut
es
  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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Tensorflow與RNN、雙向LSTM等的踩坑記錄及解決

    Tensorflow與RNN、雙向LSTM等的踩坑記錄及解決

    這篇文章主要介紹了Tensorflow與RNN、雙向LSTM等的踩坑記錄及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • Python虛擬環(huán)境venv實戰(zhàn)過程詳解

    Python虛擬環(huán)境venv實戰(zhàn)過程詳解

    Python的虛擬環(huán)境可以幫助我們在同一臺機(jī)器上,同時使用不同的Python版本和庫,方便管理和開發(fā),下面這篇文章主要給大家介紹了關(guān)于Python虛擬環(huán)境venv的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • Python中的shutil標(biāo)準(zhǔn)庫用法解析

    Python中的shutil標(biāo)準(zhǔn)庫用法解析

    這篇文章主要介紹了Python中的shutil標(biāo)準(zhǔn)庫用法解析,shutil模塊提供了許多關(guān)于文件和文件集合的高級操作,特別提供了支持文件復(fù)制和刪除的功能,需要的朋友可以參考下
    2023-09-09
  • 解決pycharm 安裝numpy失敗的問題

    解決pycharm 安裝numpy失敗的問題

    今天小編就為大家分享一篇解決pycharm 安裝numpy失敗的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python?PyQt5中QButtonGroup的詳細(xì)用法解析與應(yīng)用實戰(zhàn)記錄

    python?PyQt5中QButtonGroup的詳細(xì)用法解析與應(yīng)用實戰(zhàn)記錄

    在PyQt5中,QButtonGroup是一個用于管理按鈕互斥性和信號槽連接的類,它可以將多個按鈕劃分為一個組,管理按鈕的選中狀態(tài)和ID,本文詳細(xì)介紹了QButtonGroup的創(chuàng)建、使用方法和實際應(yīng)用案例,適合需要在PyQt5項目中高效管理按鈕組的開發(fā)者
    2024-10-10
  • python之從文件讀取數(shù)據(jù)到list的實例講解

    python之從文件讀取數(shù)據(jù)到list的實例講解

    下面小編就為大家分享一篇python之從文件讀取數(shù)據(jù)到list的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • python一行輸入多值的實現(xiàn)詳解

    python一行輸入多值的實現(xiàn)詳解

    開發(fā)人員通常想要用戶在一行中輸入多個值或者輸入。在python中有兩種方式讓用戶在一行中輸入多個值或者輸入,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-09-09
  • python、java等哪一門編程語言適合人工智能?

    python、java等哪一門編程語言適合人工智能?

    哪一門編程語言適合人工智能?這篇文章主要為大家詳細(xì)介紹了python編程語言適合人工智能的原因、優(yōu)點,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Python中xrange與yield的用法實例分析

    Python中xrange與yield的用法實例分析

    這篇文章主要介紹了Python中xrange與yield的用法,結(jié)合實例形式較為詳細(xì)的分析了range和xrange功能、使用方法與相關(guān)注意事項,需要的朋友可以參考下
    2017-12-12
  • python支持?jǐn)帱c續(xù)傳的多線程下載示例

    python支持?jǐn)帱c續(xù)傳的多線程下載示例

    這篇文章主要介紹了python支持?jǐn)帱c續(xù)傳的多線程下載示例,大家參考使用吧
    2014-01-01

最新評論

合川市| 图木舒克市| 秦皇岛市| 江都市| 榆社县| 兴安盟| 当阳市| 阿合奇县| 饶平县| 仁寿县| 炉霍县| 宁武县| 肇东市| 迁安市| 台北市| 阿拉尔市| 西乌珠穆沁旗| 郧西县| 峡江县| 丰镇市| 克拉玛依市| 吉木乃县| 长治市| 甘谷县| 永善县| 大兴区| 巨鹿县| 安顺市| 芦溪县| 南开区| 漳浦县| 石河子市| 石狮市| 荃湾区| 泰安市| 安国市| 万盛区| 哈密市| 贵溪市| 平南县| 曲水县|