首页 > 代码库 > Beginning Python From Novice to Professional (1) - 数字和表达式

Beginning Python From Novice to Professional (1) - 数字和表达式

数字和表达式

加减乘除:

>>> 2+2
4
>>> 100-50
50
>>> 3*5
15
>>> 1/2
0
>>> 1.0/2.0
0.5
求余、乘方:

>>> 1%2
1
>>> 10%3
1
>>> 2**3
8
>>> -3**2
-9
>>> (-3)**2
9
十六进制、八进制:

>>> 0xff
255
>>> 020
16
变量:

>>> x=3
>>> x*2
6
获取输入:

>>> x=input("x: ")
x: 4
>>> x*2
8
函数:

>>> pow(2,3)
8
>>> abs(-10)
10

Beginning Python From Novice to Professional (1) - 数字和表达式