欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

中文說明:不帶參數(shù)時,返回當前范圍內(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 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)文章

  • Python可視化模塊altair的使用詳解

    Python可視化模塊altair的使用詳解

    Altair被稱為是統(tǒng)計可視化庫,因為它可以通過分類匯總、數(shù)據(jù)變換、數(shù)據(jù)交互、圖形復(fù)合等。本文和大家聊一下Python當中的altair可視化模塊,并且通過調(diào)用該模塊來繪制一些常見的圖表,感興趣的可以了解一下
    2022-07-07
  • Python中bisect的使用方法

    Python中bisect的使用方法

    這篇文章主要介紹了Python中bisect的使用方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友們下面隨著小編來一起學(xué)習學(xué)習吧
    2019-12-12
  • Python實現(xiàn)朗讀在線音頻和本地音頻

    Python實現(xiàn)朗讀在線音頻和本地音頻

    在日常的Python軟件開發(fā)中,我們經(jīng)常會遇到一個非常重要的功能需求——讓程序能夠讀取并顯示文本內(nèi)容,下面我們就來學(xué)習一下Python實現(xiàn)朗讀音頻的具體操作吧
    2024-03-03
  • django+echart數(shù)據(jù)動態(tài)顯示的例子

    django+echart數(shù)據(jù)動態(tài)顯示的例子

    今天小編就為大家分享一篇django+echart數(shù)據(jù)動態(tài)顯示的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Python中的變量賦值

    Python中的變量賦值

    這篇文章主要介紹了Python中的變量賦值,Python中的變量在使用中很流暢,可以不關(guān)注類型,任意賦值,對于開發(fā)來說效率得到了提升,但不了解其中的機理,往往也會犯一些小錯,讓開發(fā)進行的不那么流暢,本文就從語言設(shè)計和底層原理的角度,帶大家理解Python中的變量。
    2021-10-10
  • Python入門:認識列表和元組

    Python入門:認識列表和元組

    這篇文章主要介紹了簡單了解python列表和元組的入門,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習或者工作具有一定的參考學(xué)習價值,需要的朋友可以參考下
    2021-10-10
  • 在python中實現(xiàn)求輸出1-3+5-7+9-......101的和

    在python中實現(xiàn)求輸出1-3+5-7+9-......101的和

    這篇文章主要介紹了在python中實現(xiàn)求輸出1-3+5-7+9-......101的和,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Python中單元測試的快速入門指南

    Python中單元測試的快速入門指南

    在這篇文章中,我們會深入探討Python單元測試的各個方面,包括它的基本概念、基礎(chǔ)知識、實踐方法、高級話題,感興趣的小伙伴可以跟隨小編一起學(xué)習一下
    2023-07-07
  • Python實現(xiàn)多腳本處理定時運行

    Python實現(xiàn)多腳本處理定時運行

    這篇文章主要介紹了Python實現(xiàn)多腳本處理定時運行,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • 淺談dataframe兩列相乘構(gòu)造新特征

    淺談dataframe兩列相乘構(gòu)造新特征

    這篇文章主要介紹了dataframe兩列相乘構(gòu)造新特征,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-05-05

最新評論