正在用Python进行各类剖析的时分,咱们会用到各类百般的函数,比方,咱们用SQL时,常常应用join、max等各类函数,那末想看Python能否有这个函数,这个时分可能年夜局部人会baidu,那末若何没有应用baidu,而用Python自身来查找函数,学习函数的用法呢?
这里还能够应用help函数:(保举学习:Python视频教程)
import math help(math)
help函数会失去一个带有阐明的函数列表,以下:
假如仍是对函数没有是特地理解,能够到办法的文件中去看函数的界说,行使***.__file__查看地位,而后关上后缀名为.py的文件。
import random random.__file__
后果为:这样就能够到这个py文件中查看源码
'D:\\Anaconda2\\envs\\py3\\lib\\random.py'
这里需求留意一下:
***.pyc的文件是编译后的文件,关上是看没有懂的,以是要看***.py文件。
正在外面能够搜想看的函数,详细的界说,比方说,我搜了expovariate函数,上面把该办法贴进去,这样就能够看到该办法是若何申明的辣,这样是否是也很不便,并且理解的愈加透辟呢~
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
更多Python相干技巧文章,请拜访Python教程栏目进行学习!
以上就是若何查看python内置函数源码的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!