日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:一分鐘學會如何查看Python內(nèi)置函數(shù)的用法及其源碼

在用Python進行各種分析的時候,我們會用到各種各樣的函數(shù),比如,我們用SQL時,經(jīng)常使用join、max等各種函數(shù),那么想看Python是否有這個函數(shù),這個時候可能大部分人會百度,那么如何不使用百度,而用Python本身來查找函數(shù),學習函數(shù)的用法呢?下面,小白就總結(jié)一下自己一些經(jīng)歷~

創(chuàng)新互聯(lián)公司2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計制作、成都網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元天祝藏族自治做網(wǎng)站,已為上家服務(wù),為天祝藏族自治各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220

比如,我們在用math模塊,但是不知道這個模塊下是否有自己常用的函數(shù),那么如何做呢?

方法一

import math
dir(math)

首先,我們導(dǎo)入這個模塊,使用dir函數(shù),就可以看到,這個模塊下都有哪些函數(shù)。

['__doc__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'acos',
 'acosh',
 'asin',
 'asinh',
 'atan',
 'atan2',
 'atanh',
 'ceil',
 'copysign',
 'cos',
 'cosh',
 'degrees',
 'e',
 'erf',
 'erfc',
 'exp',
 'expm1',
 'fabs',
 'factorial',
 'floor',
 'fmod',
 'frexp',
 'fsum',
 'gamma',
 'gcd',
 'hypot',
 'inf',
 'isclose',
 'isfinite',
 'isinf',
 'isnan',
 'ldexp',
 'lgamma',
 'log',
 'log10',
 'log1p',
 'log2',
 'modf',
 'nan',
 'pi',
 'pow',
 'radians',
 'sin',
 'sinh',
 'sqrt',
 'tan',
 'tanh',
 'tau',
 'trunc']

這種方法是得到一個函數(shù)列表,當然,這里還可以使用help函數(shù):

import math
help(math)

如果還是對函數(shù)不是特別了解,可以到方法的文件中去看函數(shù)的定義,利用***.__file__查看位置,然后打開后綴名為.py的文件。

import random
random.__file__

結(jié)果為:這樣就可以到這個py文件中查看源碼

'D:\\Anaconda2\\envs\\py3\\lib\\random.py'

這里需要注意一下:

***.pyc的文件是編譯后的文件,打開是看不懂的,所以要看***.py文件。

在里面可以搜想看的函數(shù),具體的定義,比如說,搜了expovariate函數(shù),下面把該方法貼出來,這樣就可以看到該方法是如何聲明的辣,這樣是不是也很方便,而且了解的更加透徹呢~

def expovariate(self, lambd):
        """Exponential distribution.
        lambd is 1.0 divided by the desired mean.  It should be
        nonzero.  (The parameter would be called "lambda", but that is
        a reserved word in Python.)  Returned values range from 0 to
        positive infinity if lambd is positive, and from negative
        infinity to 0 if lambd is negative.
        """
        # lambd: rate lambd = 1/mean
        # ('lambda' is a Python reserved word)
 
        # we use 1-random() instead of random() to preclude the
        # possibility of taking the log of zero.
        return -_log(1.0 - self.random())/lambd

新聞標題:創(chuàng)新互聯(lián)Python教程:一分鐘學會如何查看Python內(nèi)置函數(shù)的用法及其源碼
本文網(wǎng)址:http://m.5511xx.com/article/dpdogog.html