新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python內(nèi)建函數(shù)在哪里
python中內(nèi)置了很多函數(shù),這些函數(shù)實(shí)現(xiàn)了很多的功能。

比如,我們在用math模塊,但是不知道這個(gè)模塊下是否有自己常用的函數(shù),那么如何做呢?
方法一
import math dir(math)
首先,我們導(dǎo)入這個(gè)模塊,使用dir函數(shù),就可以看到,這個(gè)模塊下都有哪些函數(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']
這種方法是得到一個(gè)函數(shù)列表,當(dāng)然,這里還可以使用help函數(shù):
import math help(math)
如果還是對函數(shù)不是特別了解,可以到方法的文件中去看函數(shù)的定義,利用***.__file__查看位置,然后打開后綴名為.py的文件。
import random random.__file__
結(jié)果為:這樣就可以到這個(gè)py文件中查看源碼
'D:\\Anaconda2\\envs\\py3\\lib\\random.py'
文章題目:創(chuàng)新互聯(lián)Python教程:python內(nèi)建函數(shù)在哪里
新聞來源:http://m.5511xx.com/article/cdepidg.html


咨詢
建站咨詢
