常用运算:加、减、乘、除(取小数)、整除(地板除//);
>>> 1+1
2
>>> 1-1
0
>>> 1*2
2
>>> 1/2
0.5
>>> 1//2
0
>>> 9//10 #底板除,向下取
0
整除(int());round(内置函数)四舍五入0.5的时候要注意并没有入一位
>>> int(1/3)
0
>>> int(9/10)
0
>>> round(0.9,0)
1.0
>>> round(0.5,0)
0.0
>>> round(0.51,0)
1.0
除法保留指定小数位数
>>> round(1/3,2)
0.33
取余%
>>> 4%3
1
同时取商和余数
>>> divmod(4,3)
(1, 1)
添加元组,取第0位的值,或者第1位的值
>>> divmod(9,4)[1]
1
>>> divmod(9,4)[0]
2
>>>
max() 求一个最大值的方法
>>> max([1,2,3,43,45])
45
pow() 两个参数下是a的b次方;三个参数下是a的b次方除以c取余数
>>> import math #15.导入库,库名叫math
>>> math.pow(2,3)
8.0
>>>
pow(x, y, z=None, /)
Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
Some types, such as ints, are able to use a more efficient algorithm when
invoked using the three argument form.
>>> pow(2,3) #2的3次方
8
>>> pow(2,3,2) #2的3次方除以2的余数
0
>>> pow(2,3,3) #2的3次方除以3的余数
2
>>> math.sqrt(4) #开平方
2.0
>>> math.sqrt(8)
2.8284271247461903
>>>
>>> math.pi #π
3.141592653589793
# math.pow和pow不是一个东西,内置的pow有三个参数,math.pow只有两个参数。
>>> ord("a") #ord把一个字母或者字符串算出一个unicode数字,可逆
97
>>> chr(97)
'a'
# ascii码256个字符128个常见字符,A-Z 65~90 a-z 97~122;a>A,比的是Ascii,不记得可以用ord(" ")算一下。
divmod()
>>> divmod(11,2) #divmod(11除以2)返回(商,余数)
(5, 1)
>>> divmod(11,2)[1] #取索引1位置的值--余数
1
>>> divmod(11,2)[0] #取索引2位置的值--商