python基础学习-math的学习

本文介绍了Python中的math模块,包括获取π值、三角函数sin和cos、方根函数pow等,并通过实例展示了其使用方法。math模块提供了丰富的数学函数,如弧度与角度转换、对数、指数等,适用于各种数学计算需求。
摘要由CSDN通过智能技术生成

python中的math跟java里面的math类很像

用math得到pi的值

>>> import math
>>> print(math.pi)
3.141592653589793

用math求sin函数

>>> print(math.sin(math.pi/6))
0.49999999999999994

用math求cos函数

>>> print(math.cos(math.pi/3))
0.5000000000000001

用math求方pow,跟**一样

>>> print(math.pow(2,4))
16.0

>>> print(2**4)
16

这里有点不同的原因是math的pow的返回值是floa类型的,而2**3的结果是整型的

其他还是很多的math的函数:

>>> help(math)
Help on built-in module math:


NAME
    math


DESCRIPTION
    This module is always available.  It provides access to the
    mathematical functions defined by the C standard.


FUNCTIONS
    acos(...)
        acos(x)
        
        Return the arc cosine (measured in radians) of x.
    
    acosh(...)
        acosh(x)
        
        Return the inverse hyperbolic cosine of x.
    
    asin(...)
        asin(x)
        
        Return the arc sine (measured in radians) of x.
    
    asinh(...)
     

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值