Python——math模块
Python——math模块
文章目录
- Python——math模块
- 数论与表示函数
- m a t h . f a c t o r i a l ( n ) math.factorial(n) math.factorial(n)
- m a t h . f l o o r ( x ) math.floor(x) math.floor(x)
- m a t h . c e i l ( x ) math.ceil(x) math.ceil(x)
- m a t h . g c d ( ∗ i n t e g e r s ) math.gcd(*integers) math.gcd(∗integers)
- m a t h . l c m ( ∗ i n t e g e r s ) math.lcm(*integers) math.lcm(∗integers)
- 幂函数与对数函数
数论与表示函数
m a t h . f a c t o r i a l ( n ) math.factorial(n) math.factorial(n)
R e t u r n n f a c t o r i a l a s a n i n t e g e r . R a i s e s V a l u e E r r o r i f n i s n o t i n t e g r a l o r i s n e g a t i v e . Return n factorial as an integer. Raises ValueError if n is not integral or is negative. Returnnfactorialasaninteger.RaisesValueErrorifnisnotintegralorisnegative.
以整数形式返回n阶乘。如果n不是整数或为负,则引发ValueError
m a t h . f l o o r ( x ) math.floor(x) math.floor(x)
返回 x 的向下取整,小于或等于 x 的最大整数。如果 x 不是浮点数,则委托给 x.floor ,它应返回一个 Integral 值
m a t h . c e i l ( x ) math.ceil(x) math.ceil(x)
返回 x 的向上取整,即大于或等于 x 的最小的整数。如果 x 不是浮点数,委托给 x.ceil ,它应该返回一个 Integral 的值。
m a t h . g c d ( ∗ i n t e g e r s ) math.gcd(*integers) math.gcd(∗integers)
返回给定的整数参数的最大公约数。 如果有一个参数非零,则返回值将是能同时整除所有参数的最大正整数。 如果所有参数为零,则返回值为 0。 不带参数的 gcd() 返回 0。
m a t h . l c m ( ∗ i n t e g e r s ) math.lcm(*integers) math.lcm(∗integers)
返回给定的整数参数的最小公倍数。 如果所有参数均非零,则返回值将是为所有参数的整数倍的最小正整数。 如果参数之一为零,则返回值为 0。 不带参数的 lcm() 返回 1。
幂函数与对数函数
m a t h . l o g ( x [ , b a s e ] ) math.log(x[, base]) math.log(x[,base])
使用一个参数,返回 x 的自然对数(底为 e )。
使用两个参数,返回给定的 base 的对数 x ,计算为 log(x)/log(base) 。
m a t h . s q r t ( x ) math.sqrt(x) math.sqrt(x)
返回 x 的平方根。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!