# 導入模塊
import math
#dir(module):可以通過它查看任何模塊中所包含的工具
print(dir(math))
# math 是python中內置的數學模塊,封裝了許多浮點數的數學運算函數
# 可以讓我們查看每個函數的使用方法
help(math.pow)
# 冪運算:求2的5次方 ,其它寫法 2**5,內置函數pow(2,5),math.pow(2,5)
print(2**5)
print(pow(2, 5))
print(math.pow(2, 5))
# factoria用於查找給定數字的階乘,它接受正整數並返回數字的階乘
# 該方法僅接受整數(正)值,如果該值是負數或浮點數,則返回「 ValueError」
# 如果數字為0,其階乘將為1
print(math.factorial(1))
# 向下取整
b = 2.353466643
print(math.floor(b))
# 向上取整
print(math.ceil(b))
# round() python內置函數,實現四捨五入到指定位數
print(round(b, 2))
# 開平方
c = 9
print(math.sqrt(c))
# 三角函數: 弧度 Π=180°,python中不會之間寫多少度,用math.pi值
print(math.sin(math.pi / 6))
print(math.cos(math.pi / 3))
print(math.tan(math.pi / 2))
# 求絕對值(小數)
print(math.fabs(-0.23))
# python內置函數,求絕對值
print(abs(-2))
# 拆分小數和整數
print(math.modf(3.14))
因小白實力有限,文中如有錯誤,歡迎公眾號後臺回覆說明,便於修改,謝謝指教||如有侵權,請聯繫刪除,謝謝!||
Long-press QR code to transfer me a reward
喜歡我的文章,那就給我一點動力
As required by Apple's new policy, the Reward feature has been disabled on Weixin for iOS. You can still reward an Official Account by transferring money via QR code.