1.math簡介?
>>>?import?math
>>>dir(math)???????????#這句可查看所有函數名列表
['__doc__',?'__name__',?'__package__',?'acos',?'acosh',?'asin',?'asinh',?'atan',?'atan2',?'atanh',?'ceil',?'copysign',?'cos',?'cosh',?'degrees',?'e',?'erf',?'erfc',?'exp',?'expm1',?'fabs',?'factorial',?'floor',?'fmod',?'frexp',?'fsum',?'gamma',?'hypot',?'isinf',?'isnan',?'ldexp',?'lgamma',?'log',?'log10',?'log1p',?'modf',?'pi',?'pow',?'radians',?'sin',?'sinh',?'sqrt',?'tan',?'tanh',?'trunc']
>>>help(math)?????????#查看具體定義及函數0原型
>>>help(math.function)?#查看math模塊下函數的功能
2.常用函數
ceil(x)?取頂
????Return?the?ceiling?of?x?as?a?float.
????This?is?the?smallest?integral?value?>=?x.
floor(x)?取底
Return?the?floor?of?x?as?a?float.
This?is?the?largest?integral?value?<=?x.
fabs(x)?取絕對值
Return?the?absolute?value?of?the?float?x.
factorial?(x)?階乘
Find?x!.?Raise?a?ValueError?if?x?is?negative?or?non-integral.
hypot(x,y)??求直角三角形的斜邊長
Return?the?Euclidean?distance,?sqrt(x*x?+?y*y)
pow(x,y)?x的y次方
Return?x**y?(x?to?the?power?of?y).
sqrt(x)?開平方
Return?the?square?root?of?x.
log(x[,base])
Return?the?logarithm?of?x?to?the?given?base.
?If?the?base?not?specified,?returns?the?natural?logarithm?(base?e)?of?x.
log10(x)
Return?the?base?10?logarithm?of?x.
trunc(x)??截斷取整數部分
Truncates?x?to?the?nearest?Integral?toward?0.?Uses?the?__trunc__?magic?method.
isnan?(x)??判斷是否NaN(not?a?number)
Check?if?float?x?is?not?a?number?(NaN)
degrees(x)?弧度轉角度
Convert?angle?x?from?radians?to?degrees.
radians(x)?角度轉弧度
Convert?angle?x?from?degrees?to?radians.?
另外該模塊定義了兩個常量:?
e?=?2.718281828459045
pi?=?3.141592653589793