• 技术文章 >常见问题 >Python常见问题

    python内建函数在哪里

    silencementsilencement2019-09-21 16:02:19原创3883

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

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

    方法一

    1

    2

    import math

    dir(math)

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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    ['__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函数:

    1

    2

    import math

    help(math)

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

    1

    2

    import random

    random.__file__

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

    1

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

    专题推荐:内建函数
    上一篇:如何下载安装python3.6 下一篇:学习python用python2还是python3

    相关文章推荐

    • python内置函数在哪• python的时间函数怎么用• python的print函数不要换行怎么写• python的help函数怎么退出

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网