python内建函数在哪里

445次阅读
没有评论

python内建函数在哪里

python中内置了很多函数,这些函数实现了很多的功能。

比如,我们在用math模块,但是不知道这个模块下是否有自己常用的函数,那么如何做呢?

方法一

import math
dir(math)

首先,我们导入这个模块,使用dir函数,就可以看到,这个模块下都有哪些函数。

['__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']

这种方法是得到一个函数列表,当然,这里还可以使用help函数:

import math
help(math)

python内建函数在哪里

如果还是对函数不是特别了解,可以到方法的文件中去看函数的定义,利用***.__file__查看位置,然后打开后缀名为.py的文件。

import random
random.__file__

结果为:这样就可以到这个py文件中查看源码

'D:\\Anaconda2\\envs\\py3\\lib\\random.py'
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2019-09-28发表,共计1368字。
新手QQ群:570568346,欢迎进群讨论 Python51学习
评论(没有评论)