码迷,mamicode.com
首页 > 编程语言 > 详细

python math模块

时间:2015-09-14 22:47:12      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

1.math简介 

>>> import math

>>>dir(math)           #这句可查看所有函数名列表

[‘__doc__‘, ‘__name__‘, ‘__package__‘, ‘acos‘, ‘acosh‘, ‘asin‘, ‘asinh‘, ‘atan‘, ‘atan2‘, ‘atanh‘, ‘ceil‘, ‘copysign‘, ‘cos‘, ‘cosh‘, ‘degrees‘, ‘e‘, ‘erf‘, ‘erfc‘, ‘exp‘, ‘expm1‘, ‘fabs‘, ‘factorial‘, ‘floor‘, ‘fmod‘, ‘frexp‘, ‘fsum‘, ‘gamma‘, ‘hypot‘, ‘isinf‘, ‘isnan‘, ‘ldexp‘, ‘lgamma‘, ‘log‘, ‘log10‘, ‘log1p‘, ‘modf‘, ‘pi‘, ‘pow‘, ‘radians‘, ‘sin‘, ‘sinh‘, ‘sqrt‘, ‘tan‘, ‘tanh‘, ‘trunc‘]

>>>help(math)         #查看具体定义及函数0原型

>>>help(math.function) #查看math模块下函数的功能

2.常用函数

ceil(x) 取顶

    Return the ceiling of x as a float.

    This is the smallest integral value >= x.

floor(x) 取底

Return the floor of x as a float.

This is the largest integral value <= x.

fabs(x) 取绝对值

Return the absolute value of the float x.

factorial (x) 阶乘

Find x!. Raise a ValueError if x is negative or non-integral.

hypot(x,y)  求直角三角形的斜边长

Return the Euclidean distance, sqrt(x*x + y*y)

pow(x,y) x的y次方

Return x**y (x to the power of y).

sqrt(x) 开平方

Return the square root of x.

log(x[,base])

Return the logarithm of x to the given base.

 If the base not specified, returns the natural logarithm (base e) of x.

log10(x)

Return the base 10 logarithm of x.

trunc(x)  截断取整数部分

Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.

isnan (x)  判断是否NaN(not a number)

Check if float x is not a number (NaN)

degrees(x) 弧度转角度

Convert angle x from radians to degrees.

radians(x) 角度转弧度

Convert angle x from degrees to radians. 

另外该模块定义了两个常量: 

e = 2.718281828459045

pi = 3.141592653589793

python math模块

标签:

原文地址:http://www.cnblogs.com/godiness/p/4808324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!