查看内置函数dir(__builtins__)
/ 转义字符。
r 原始字符
浮点数不是百分之百准确。
需要使用函数转换
improt decimal
a=decimal.Decimal('0.1')
b=decimal.Decimal('0.2')
print(a+b)
5e-05科学计数法, 5x10的负5次方。
复数包含一个实部虚部
x=1+2j
x.real获取实部
x.imag获取虚部
x//y x/y的结果(地板除)向下取整数。
函数divmod(x,y)返回(x//y,x%y)地板除和取模。
函数abs(5)取绝对值
int('22')将数值转换成整数。不是四舍五入
float('')转换成浮点数。
complex('1+2j')转换成复数。
pow(2,3)的幂运算2的3次方
2**3 2的3次方 两个一样的
pow(2,3,5)第三个参数是取余的
布尔类型
bool('sddsa')
bool(false)
bool("")
false
bool(" ")
true
以下都是FALSE的结果:
定义为FALSE的对象:none和false
值为0的数字类型:0,0.0,0j,decimal(0),fraction(0,1)
空的序列和集合:‘’,(),{},[],set(),range(0)
1==True
0==False
逻辑运算符
and 左右两边都是True才True
or左右两边其中一个为True,结果为true
not 如果操作数为true,结果为false
如果操作数为FALSE,结果为true
运算符优先级 可以使用()优先计算。
or and not < >
+ -