python常用数学函数

#-*-coding:utf-8-*-
'''
Created on 2016年3月20日

@author: Zroad
'''

"""
一、常见数学常量:pi,e等
"""
import math

print "math.pi=",math.pi
print "math.e=",math.e

"""
二、常用数学函数
"""
print "math.sin(pi)=",math.sin(math.pi)
print "math.tan(pi)=",math.tan(math.pi)

print "math.sqrt(4)=",math.sqrt(4) #2.0

#不在math模块下的内置数学函数
print "pow(2,5)=",pow(2,5) #32.0
print "abs(-45)=",abs(-45),abs(-0.09) #45,0.09

"""
三、sum函数:
1、sum(...)
    sum(sequence[, start]) -> value

    Return the sum of a sequence of numbers (NOT strings) plus the value
    of parameter 'start' (which defaults to 0).  When the sequence is
    empty, return start.
2、sum函数中传入的参数序列不能嵌套
"""
print sum((1,2,3,4)) #10
print sum([1,2,3,4]) #10
print sum([2,4,6,8],3) #23
print sum([2,4,6,8],1000) #1020
#print sum([2,4,6,8,[10,20]])

"""
四、求最大、最小值:
min(...)
    min(iterable[, key=func]) -> value
    min(a, b, c, ...[, key=func]) -> value

    With a single iterable argument, return its smallest item.
    With two or more arguments, return the smallest argument.
"""
print max([1,2,3,4])  #4
print max(1,2,3,4,5)  #5
print max([1,2,3,4,[5,6]]) #[5,6]
print max([1,2,3,4,[0,5]]) #[0,5]
print max([1,2,3,4,5,[0,0]]) #[0,0]
print max([1,2,3,4,5,{6:7}]) #{6: 7}
print "--------------------"

print min([1,2,3,4])  #1
print min(1,2,3,4,5)  #1
print min([1,2,3,4,[5,6]]) #1
print min([1,2,3,4,[0,5]]) #1
print min([1,2,3,4,5,[0,0]]) #[0,0]
print min([1,2,3,4,5,{6:7}]) #1

"""
五、round函数:提供数据的四舍五入方法
"""
print round(2.25) #2.0
print round(2.75) #3.0
print round(-2.25) #-2.0
print round(-2.75) #-3.0
print round(3.14159399482,2) #3.14
print round(3.14159399482,3) #3.142
print round(3.14159399482,4) #3.1416
print round(3.14159399482,5) #3.14159
print round(-3.14159399482,2) #-3.14
print round(-3.14159399482,3) #-3.142
print round(-3.14159399482,4) #-3.1416
print round(-3.14159399482,5) #-3.14159
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值