python3 math module_科学网—Python 3: Module math - mathematical functions - 刘洋洋的博文

这篇博客介绍了Python中的math库,包括math.floor()、math.sqrt()、math.pow()、math.log10()和math.exp()等函数的用法,展示了如何进行地板取整、平方根、指数和对数计算。还提到了math.isnan()用于检查是否为NaN,以及math.pi和math.e的值。这些函数在数值计算和科学计算中非常实用。
摘要由CSDN通过智能技术生成

>>> import math

# math.floor(x) returns the floor of x as a float, the largest integer value less than or equal to x.

>>> math.floor(9.2)

9.0

# math.sqrt(x) returns the square root of x.

>>> math.sqrt(81)

9.0

# math.pow(x,y) returns x raised to the power y.

>>> math.pow(2,3)

8.0

# math.log10(x) returns the base-10 logarithm of x.

>>> math.log10(100)

2.0

# math.exp(x) returns e**x.

>>> math.exp(2)

7.38905609893065

# check if the float x is a NaN

>>> math.isnan(x)

#equivalent to the output of float('nan').

>>> math.nan  # python3

nan

>>> math.pi

3.141592653589793

>>> math.e

2.718281828459045

转载本文请联系原作者获取授权,同时请注明本文来自刘洋洋科学网博客。

链接地址:http://blog.sciencenet.cn/blog-3031432-1015385.html

上一篇:Python: operators

下一篇:Python 2: strings

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值