ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x

copysign:把y的正负号加到x前面,可以使用0

cos:求x的余弦,x必须是弧度

degrees:把x从弧度转换成角度

e:表示一个常量

exp:返回math.e,也就是2.71828的x次方

expm1:返回math.e的x(其值为2.71828)次方的值减1

fabs:返回x的绝对值

factorial:取x的阶乘的值

floor:取小于等于x的最大的整数值,如果x是一个整数,则返回自身

fmod:得到x/y的余数,其值是一个浮点数

frexp:返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围

fsum:对迭代器里的每个元素进行求和操作

gcd:返回x和y的最大公约数

hypot:如果x是不是无穷大的数字,则返回True,否则返回False

isfinite:如果x是正无穷大或负无穷大,则返回True,否则返回False

isinf:如果x是正无穷大或负无穷大,则返回True,否则返回False

isnan:如果x不是数字True,否则返回False

ldexp:返回x*(2**i)的值

log:返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)

log10:返回x的以10为底的对数

log1p:返回x+1的自然对数(基数为e)的值

log2:返回x的基2对数

modf:返回由x的小数部分和整数部分组成的元组

pi:数字常量,圆周率

pow:返回x的y次方,即x**y

radians:把角度x转换成弧度

sin:求x(x为弧度)的正弦值

sqrt:求x的平方根

tan:返回x(x为弧度)的正切值

trunc:返回x的整数部分

ceil

  1. #取大于等于x的最小的整数值,如果x是一个整数,则返回x
  2. ceil(x)
  3. Return the ceiling of x as an int.
  4. This is the smallest integral value >= x.
  1. >>> math.ceil(4.01)
  2. 5
  3. >>> math.ceil(4.99)
  4. 5
  5. >>> math.ceil(-3.99)
  6. -3
  7. >>> math.ceil(-3.01)
  8. -3

copysign

  1. #把y的正负号加到x前面,可以使用0
  2. copysign(x, y)
  3. Return a float with the magnitude (absolute value) of x but the sign
  4. of y. On platforms that support signed zeros, copysign(1.0, -0.0)
  5. returns -1.0.
  1. >>> math.copysign(2,3)
  2. 2.0
  3. >>> math.copysign(2,-3)
  4. -2.0
  5. >>> math.copysign(3,8)
  6. 3.0
  7. >>> math.copysign(3,-8)
  8. -3.0

cos

  1. #求x的余弦,x必须是弧度
  2. cos(x)
  3. Return the cosine of x (measured in radians).
  1. #math.pi/4表示弧度,转换成角度为45度
  2. >>> math.cos(math.pi/4)
  3. 0.7071067811865476
  4. math.pi/3表示弧度,转换成角度为60
  5. >>> math.cos(math.pi/3)
  6. 0.5000000000000001
  7. math.pi/6表示弧度,转换成角度为30
  8. >>> math.cos(math.pi/6)
  9. 0.8660254037844387

degrees

  1. #把x从弧度转换成角度
  2. degrees(x)
  3. Convert angle x from radians to degrees.
  1. >>> math.degrees(math.pi/4)
  2. 45.0
  3. >>> math.degrees(math.pi)
  4. 180.0
  5. >>> math.degrees(math.pi/6)
  6. 29.999999999999996
  7. >>> math.degrees(math.pi/3)
  8. 59.99999999999999

e

  1. #表示一个常量
  1. >>> math.e
  2. 2.718281828459045

exp

  1. #返回math.e,也就是2.71828的x次方
  2. exp(x)
  3. Return e raised to the power of x.
  1. >>> math.exp(1)
  2. 2.718281828459045
  3. >>> math.exp(2)
  4. 7.38905609893065
  5. >>> math.exp(3)
  6. 20.085536923187668

expm1

  1. #返回math.e的x(其值为2.71828)次方的值减1
  2. expm1(x)
  3. Return exp(x)-1.
  4. This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.
  1. >>> math.expm1(1)
  2. 1.718281828459045
  3. >>> math.expm1(2)
  4. 6.38905609893065
  5. >>> math.expm1(3)
  6. 19.085536923187668

fabs

  1. #返回x的绝对值
  2. fabs(x)
  3. Return the absolute value of the float x.
  1. >>> math.fabs(-0.003)
  2. 0.003
  3. >>> math.fabs(-110)
  4. 110.0
  5. >>> math.fabs(100)
  6. 100.0

factorial

  1. #取x的阶乘的值
  2. factorial(x) -> Integral
  3. Find x!. Raise a ValueError if x is negative or non-integral.
  1. >>> math.factorial(1)
  2. 1
  3. >>> math.factorial(2)
  4. 2
  5. >>> math.factorial(3)
  6. 6
  7. >>> math.factorial(5)
  8. 120
  9. >>> math.factorial(10)
  10. 3628800

floor

  1. #取小于等于x的最大的整数值,如果x是一个整数,则返回自身
  2. floor(x)
  3. Return the floor of x as an int.
  4. This is the largest integral value <= x.
  1. >>> math.floor(4.1)
  2. 4
  3. >>> math.floor(4.999)
  4. 4
  5. >>> math.floor(-4.999)
  6. -5
  7. >>> math.floor(-4.01)
  8. -5

fmod

  1. #得到x/y的余数,其值是一个浮点数
  2. fmod(x, y)
  3. Return fmod(x, y), according to platform C. x % y may differ.
  1. >>> math.fmod(20,3)
  2. 2.0
  3. >>> math.fmod(20,7)
  4. 6.0

frexp

  1. #返回一个元组(m,e),其计算方式为:x分别除0.5和1,得到一个值的范围,
  2. #2**e的值在这个范围内,e取符合要求的最大整数值,然后x/(2**e),得到m的值
  3. #如果x等于0,则m和e的值都为0,m的绝对值的范围为(0.5,1)之间,不包括0.5和1
  4. frexp(x)
  5. Return the mantissa and exponent of x, as pair (m, e).
  6. m is a float and e is an int, such that x = m * 2.**e.
  7. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
  1. >>> math.frexp(10)
  2. (0.625, 4)
  3. >>> math.frexp(75)
  4. (0.5859375, 7)
  5. >>> math.frexp(-40)
  6. (-0.625, 6)
  7. >>> math.frexp(-100)
  8. (-0.78125, 7)
  9. >>> math.frexp(100)
  10. (0.78125, 7)

fsum

  1. #对迭代器里的每个元素进行求和操作
  2. fsum(iterable)
  3. Return an accurate floating point sum of values in the iterable.
  4. Assumes IEEE-754 floating point arithmetic.
  1. >>> math.fsum([1,2,3,4])
  2. 10.0
  3. >>> math.fsum((1,2,3,4))
  4. 10.0
  5. >>> math.fsum((-1,-2,-3,-4))
  6. -10.0
  7. >>> math.fsum([-1,-2,-3,-4])
  8. -10.0

gcd

  1. #返回x和y的最大公约数
  2. gcd(x, y) -> int
  3. greatest common divisor of x and y
  1. >>> math.gcd(8,6)
  2. 2
  3. >>> math.gcd(40,20)
  4. 20
  5. >>> math.gcd(8,12)
  6. 4

hypot

  1. #得到(x**2+y**2),平方的值
  2. hypot(x, y)
  3. Return the Euclidean distance, sqrt(x*x + y*y).
  1. >>> math.hypot(3,4)
  2. 5.0
  3. >>> math.hypot(6,8)
  4. 10.0

isfinite

  1. #如果x是不是无穷大的数字,则返回True,否则返回False
  2. isfinite(x) -> bool
  3. Return True if x is neither an infinity nor a NaN, and False otherwise.
  1. >>> math.isfinite(100)
  2. True
  3. >>> math.isfinite(0)
  4. True
  5. >>> math.isfinite(0.1)
  6. True
  7. >>> math.isfinite("a")
  8. >>> math.isfinite(0.0001)
  9. True

isinf

  1. #如果x是正无穷大或负无穷大,则返回True,否则返回False
  2. isinf(x) -> bool
  3. Return True if x is a positive or negative infinity, and False otherwise.
  1. >>> math.isinf(234)
  2. False
  3. >>> math.isinf(0.1)
  4. False

isnan

  1. #如果x不是数字True,否则返回False
  2. isnan(x) -> bool
  3. Return True if x is a NaN (not a number), and False otherwise.
  1. >>> math.isnan(23)
  2. False
  3. >>> math.isnan(0.01)
  4. False

ldexp

  1. #返回x*(2**i)的值
  2. ldexp(x, i)
  3. Return x * (2**i).
  1. >>> math.ldexp(5,5)
  2. 160.0
  3. >>> math.ldexp(3,5)
  4. 96.0

log

  1. #返回x的自然对数,默认以e为基数,base参数给定时,将x的对数返回给定的base,计算式为:log(x)/log(base)
  2. log(x[, base])
  3. Return the logarithm of x to the given base.
  4. If the base not specified, returns the natural logarithm (base e) of x.
  1. >>> math.log(10)
  2. 2.302585092994046
  3. >>> math.log(11)
  4. 2.3978952727983707
  5. >>> math.log(20)
  6. 2.995732273553991

log10

  1. #返回x的以10为底的对数
  2. log10(x)
  3. Return the base 10 logarithm of x.
  1. >>> math.log10(10)
  2. 1.0
  3. >>> math.log10(100)
  4. 2.0
  5. #即10的1.3次方的结果为20
  6. >>> math.log10(20)
  7. 1.3010299956639813

log1p

  1. #返回x+1的自然对数(基数为e)的值
  2. log1p(x)
  3. Return the natural logarithm of 1+x (base e).
  4. The result is computed in a way which is accurate for x near zero.
  1. >>> math.log(10)
  2. 2.302585092994046
  3. >>> math.log1p(10)
  4. 2.3978952727983707
  5. >>> math.log(11)
  6. 2.3978952727983707

log2

  1. #返回x的基2对数
  2. log2(x)
  3. Return the base 2 logarithm of x.
  1. >>> math.log2(32)
  2. 5.0
  3. >>> math.log2(20)
  4. 4.321928094887363
  5. >>> math.log2(16)
  6. 4.0

modf

  1. #返回由x的小数部分和整数部分组成的元组
  2. modf(x)
  3. Return the fractional and integer parts of x. Both results carry the sign
  4. of x and are floats.
  1. >>> math.modf(math.pi)
  2. (0.14159265358979312, 3.0)
  3. >>> math.modf(12.34)
  4. (0.33999999999999986, 12.0)

pi

  1. #数字常量,圆周率
  1. >>> print(math.pi)
  2. 3.141592653589793

pow

  1. #返回x的y次方,即x**y
  2. pow(x, y)
  3. Return x**y (x to the power of y).
  1. >>> math.pow(3,4)
  2. 81.0
  3. >>>
  4. >>> math.pow(2,7)
  5. 128.0

radians

  1. #把角度x转换成弧度
  2. radians(x)
  3. Convert angle x from degrees to radians.
  1. >>> math.radians(45)
  2. 0.7853981633974483
  3. >>> math.radians(60)
  4. 1.0471975511965976

sin

  1. #求x(x为弧度)的正弦值
  2. sin(x)
  3. Return the sine of x (measured in radians).
  1. >>> math.sin(math.pi/4)
  2. 0.7071067811865475
  3. >>> math.sin(math.pi/2)
  4. 1.0
  5. >>> math.sin(math.pi/3)
  6. 0.8660254037844386

sqrt

  1. #求x的平方根
  2. sqrt(x)
  3. Return the square root of x.
  1. >>> math.sqrt(100)
  2. 10.0
  3. >>> math.sqrt(16)
  4. 4.0
  5. >>> math.sqrt(20)
  6. 4.47213595499958

tan

  1. #返回x(x为弧度)的正切值
  2. tan(x)
  3. Return the tangent of x (measured in radians).
  1. >>> math.tan(math.pi/4)
  2. 0.9999999999999999
  3. >>> math.tan(math.pi/6)
  4. 0.5773502691896257
  5. >>> math.tan(math.pi/3)
  6. 1.7320508075688767

trunc

  1. #返回x的整数部分
  2. trunc(x:Real) -> Integral
  3. Truncates x to the nearest Integral toward 0. Uses the __trunc__ magic method.
  1. >>> math.trunc(6.789)
  2. 6
  3. >>> math.trunc(math.pi)
  4. 3
  5. >>> math.trunc(2.567)
  6. 2

python中math模块常用的方法整理的更多相关文章

  1. (转)python中math模块常用的方法整理

    原文:https://www.cnblogs.com/renpingsheng/p/7171950.html#ceil ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysig ...

  2. 【转载】python中math模块常用的方法

    转自:https://www.cnblogs.com/renpingsheng/p/7171950.html ceil #取大于等于x的最小的整数值,如果x是一个整数,则返回x ceil(x) Ret ...

  3. Python中optionParser模块的使用方法[转]

    本文以实例形式较为详尽的讲述了Python中optionParser模块的使用方法,对于深入学习Python有很好的借鉴价值.分享给大家供大家参考之用.具体分析如下: 一般来说,Python中有两个内 ...

  4. [ Python入门教程 ] Python中JSON模块基本使用方法

    JSON (JavaScript Object Notation)是一种使用广泛的轻量数据格式,Python标准库中的json模块提供了一种简单的方法来编码和解码JSON格式的数据.用于完成字符串和p ...

  5. python中time模块常用功能

    import time time模块提供了大量对时间进行处理的方法 time.time() # 获取当前时间戳,得到自1970年开始的秒数 >>>time.time() 155487 ...

  6. Python学习-32.Python中os模块的一些方法

    首先肯定是要引入os模块了. import os getcwd方法: print(os.getcwd()) 上面的语句将会输出当前的工作目录,相当于C#中的Environment.CurrentDir ...

  7. Python学习-34.Python中os模块的一些方法(二)

    stat方法: 用于获取文件信息,例如创建时间.文件大小等. import os filestate=os.stat("e:/temp/test.txt") print(files ...

  8. Python:python中math模块中提供的基本数学函数

    sin(x):求x的正弦 cos(x):求x的余弦 asin(x):求x的反正弦 acos(x):求x的反余弦 tan(x):求x的正切 atan(x):求x的反正切 hypot(x,y):求直角三角 ...

  9. 项目中常用js方法整理common.js

    抽空把项目中常用js方法整理成了common.js,都是网上搜集而来的,大家一起分享吧. var h = {}; h.get = function (url, data, ok, error) { $ ...

随机推荐

  1. JavaScript正则表达式验证大全(收集)

    以下函数调用方式: ? 1 2 3 4 function check() { var bb = document.getElementById("txt_id").value;// ...

  2. HDU 1002 A + B Problem II(高精度加法(C++/Java))

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. [bzoj4410] [Usaco2016 Feb]Fence in

    根据ccz181078大爷的题解可得(QAQ,每次肯定是断掉连续一行||一列的栅栏... 贪心地想,一个格子与外面联通,显然是先把短的边界断掉(就像mst那样 但是比较蛋疼的是,因为我们每次断的时候, ...

  4. CodeForces798-B. Mike and strings-string中的find()函数

    好久好久好久之前的一个题,今天翻cf,发现这个题没过,补一下. B. Mike and strings time limit per test 2 seconds memory limit per t ...

  5. [国嵌攻略][155][I2C用户态驱动设计]

    用户态驱动模型 用户态驱动模型首先是一个应用程序,其次是在这个用户程序中通过内核调用来驱动设备. IIC通用驱动代码 IIC通用驱动程序的代码在/drivers/i2c/i2c-dev.c中.一次读操 ...

  6. setTimeout()方法,你真的懂吗?

    今天在群里看到了一道经典的javascript题型,之前也遇到过,可是再次遇到时,还是做错,还是不理解,因此这里来做个笔记吧! 不说了,直接上代码吧 for(var i=1; i<=9; i++ ...

  7. ECharts插件的使用

    ECharts插件:官网下载echarts.js开发者可以选择源码.下载地址:http://echarts.baidu.com/download.html 下载之后,echarts.js放在js文件夹 ...

  8. DTD约束

    DTD约束 一,导入DTD方式   二,DTD语法 2)DTD语法 约束标签 <!ELEMENT 元素名称类别>或<!ELEMENT 元素名称(元素内容)> 类别: 空标签: ...

  9. tp系统常量定义

    (2013-03-06 14:16:31) 转载▼ 标签: it 是已经封装好的系统常量 主要是用在控制器下面的动作当中 这样能很大的提高我们的开发效率 主要有下面的一些      手册上面都有的   ...

  10. nxlog4go 简介 - 基于log4go的下一代go语言日志系统

    nxlog4go的项目网址: https://github.com/ccpaging/nxlog4go 项目历史 ccpaging's log4go forked from https://githu ...