简单实用的Python计算器

一 直接进行算术运算

举例如下:
>>> 3*5/2
7.5
>>> 3.0*5.0/2
7.5
>>> 3.0+5.0/2
5.5
>>> (3.0+5.0)/2
4.0
>>> 2**3
8
>>> 2**8
256
 
二 math模块提供丰富的数学函数
举例如下:
>>> import math
>>> math.cos(0.5)
0.8775825618903728
>>> math.sin(math.pi)
1.2246467991473532e-16
>>> math.sin(60)
-0.3048106211022167
>>> math.tan(1)
1.5574077246549023
>>> math.sqrt(9)
3.0
>>> math.log10(2)
0.3010299956639812
>>> math.log10(100)
2.0
>>> math.asin(0.5)
0.5235987755982989
>>> math.pow(2,8)
256.0
 
三 Python对大整数的支持
举例如下:
>>> 99**99
369729637649726772657187905628805440595668764281741102430259972423552570455277523421410650010128232727940978889548326540119429996769494359451621570193644014418071060667659301384999779999159200499899
 

猜你喜欢

转载自cakin24.iteye.com/blog/2381296
今日推荐