python 常用数学函数

发布时间:2019-08-24 09:24:13编辑:auto阅读(2011)

    python 中自带常用数学函数,使用前需加载 math 模块

    import  math

    0.常数:
                    (1) math.e    =  2.71828...
                    (2)math.pi    = 3.141592...

    1. 指数:  
                    (1)  math.pow(2, 10)    ==  2^10
                               扩展 :  math.pow(2, 3, 3)  ==  2^3%3 = 2            #  取模指数

                     ( 2 )    math.exp( 10 )        == e^10

                    (3)   math.sqrt( 10 )       == 10^0.5 == math.pow(10, 0.5)

    2.对数:  
                       ( 1 )  math.log(  数值 [, 底数] )                                      # 底数值缺失则默认为以 math.e为底数

                               math.log(4,  2)     ==  log24  = 2
                               math.log(math.e)   ==  ln e =  1

    3.取整 :
                       (1)math.ceil( 4.2 )  == 5                                            # 向上取整
            
                       (2)math.floor( 4.2 ) == 4                                          # 向下取整

                      
    4.三角函数:
                        (1) math.degrees( math.pi )  == 180.0                    # 弧度换角度
                        (2) math.radians( 60.0 )  == math.pi/3  = 1.04..      # 角度换弧度

                       【注意】:所有函数的参数都是弧度值

                         (3) math.sin(math.pi/6) == 1/2                              # sin( )
                         (4) math.cos(math.pi/3) == 1/2  #  cos( )
                         (5) math.tan(math.pi/4) == 1                                 #  tan( )

关键字