Python模块的函数用法

时间:2019-05-25 03:18:58

标签: python

我正在学习python并遇到一些问题  当我们将模块作为整体(*)或某些所需功能导入时,如何查看这些功能的用法 例如:

import math

dir(math)

['__doc__', '__file__', '__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', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']

我从math模块中获得了很多功能,但是如何使用它们会花费1 arg或更多,或者如何使用。 例如:如何使用cos或如何使用floor

我可以获得模块数学的用法,但需要模块用法中的函数。

上述

import math

dir(math)

['__doc__', '__file__', '__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', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']

就像dir()一样,寻找一些东西来了解如何使用模块内部的每个函数。

当前我在MAC上使用python 2.6和python 3.5

2 个答案:

答案 0 :(得分:0)

您可以仅使用RTFM https://docs.python.org/2.7/library/math.html ...这将是最好的方法

答案 1 :(得分:0)

尝试使用ipython,只需键入func?还是func?