本节内容数学运算:
使用终端命令进行简单数学运算
编写简单程序,print输出结果
终端输入python3,输入4+5,回车
(base) C:\Users\admin>python
Python 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 4+5
9
>>> 4-5
-1
>>> 4/5
0.8
>>> 4*5
20
>>>
进行分数,整除,除数得到小数,指数,多重幂值从右向左计算。百分号求余
>>> 1/3+2/3
1.0
>>> 1/3
0.3333333333333333
>>> 5//2
2
>>> 2/1
2.0
>>> 3**2
9
>>> 3**2**3
6561
>>> 16%3
1
输出科学计数法的数值print(3e-2)
0.03
小数的类型是浮点型float,print(type(3e-2))
<class 'float'>
type()内置函数检验数据类型
零不能作除数,例如输入11/0
,则会报错。
ZeroDivisionError: division by zero