在python中,通过导入一个名为“math”的模块,可以轻松地执行许多数学操作,该模块定义了各种函数,使我们的任务更容易。
null
1.ceil() :-此函数返回 大于数字的最小整数值 .如果数字已经是整数,则返回相同的数字。
2.楼层() :-此函数返回 小于数字的最大整数值 .如果数字已经是整数,则返回相同的数字。
# Python code to demonstrate the working of # ceil() and floor() # importing "math" for mathematical operations import math a = 2.3 # returning the ceil of 2.3 print ( "The ceil of 2.3 is : " , end = "") print (math.ceil(a)) # returning the floor of 2.3 print ( "The floor of 2.3 is : " , end = "") print (math.floor(a)) |
输出:
The ceil of 2.3 is : 3 The floor of 2.3 is : 2
3.晶圆厂() :-此函数返回 绝对值 这个数字是多少。
4.阶乘() :-此函数返回 阶乘的 这个数字是多少。如果数字不是整数,则会显示错误消息。
# Python code to demonstrate the working of # fabs() and factorial() # importing "math" for mathematical operations import math a = - 10 b = 5 # returning the absolute value. print ( "The absolute value of -10 is : " , end = "") print (math.fabs(a)) # returning the factorial of 5 print ( "The factorial of 5 is : " , end = "") print (math.factorial(b)) |
输出:
The absolute value of -10 is : 10.0 The factorial of 5 is : 120
5.文案签名(a、b) :-此函数返回带有 值为“a”,但符号为“b” .返回的值为浮点型。
6.gcd() :-此函数用于计算 2个数的最大公约数 在其论点中提到。此函数适用于python 3.5及更高版本。
# Python code to demonstrate the working of # copysign() and gcd() # importing "math" for mathematical operations import math a = - 10 b = 5.5 c = 15 d = 5 # returning the copysigned value. print ( "The copysigned value of -10 and 5.5 is : " , end = "") print (math.copysign( 5.5 , - 10 )) # returning the gcd of 15 and 5 print ( "The gcd of 5 and 15 is : " , end = "") print (math.gcd( 5 , 15 )) |
输出:
The copysigned value of -10 and 5.5 is : -5.5 The gcd of 5 and 15 is : 5
本文由 曼吉星 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END