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

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

 更新時間:2020年06月19日 16:02:36   作者:silencement  
在本篇文章里小編給大家分享的是一篇關于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.

 代碼實例

>>>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來編寫代碼時,會經常使用python自帶函數(shù)或模塊,一些不常用的函數(shù)或是模塊的用途不是很清楚,這時候就需要用到help函數(shù)來查看幫助。

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

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

help()括號內填寫參數(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.

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

相關文章

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

    Python中的shutil標準庫用法解析

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

    解決pycharm 安裝numpy失敗的問題

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

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

    在PyQt5中,QButtonGroup是一個用于管理按鈕互斥性和信號槽連接的類,它可以將多個按鈕劃分為一個組,管理按鈕的選中狀態(tài)和ID,本文詳細介紹了QButtonGroup的創(chuà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中有兩種方式讓用戶在一行中輸入多個值或者輸入,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-09-09
  • python、java等哪一門編程語言適合人工智能?

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

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

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

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

    python支持斷點續(xù)傳的多線程下載示例

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

最新評論

灌云县| 天台县| 夹江县| 宁河县| 大连市| 峨眉山市| 丁青县| 晴隆县| 保德县| 紫金县| 吴桥县| 东平县| 观塘区| 土默特左旗| 泸州市| 云安县| 凤冈县| 福贡县| 稷山县| 金坛市| 汉源县| 丹寨县| 甘肃省| 铁岭县| 桐庐县| 常山县| 吴江市| 依兰县| 读书| 卓资县| 昌平区| 盐边县| 永平县| 江门市| 漳州市| 宁蒗| 洛南县| 金堂县| 繁昌县| 石渠县| 凤城市|