运算符

  1. 加法运算及乘法运算还可以用于字符串类型
  2. 幂运算支持复数,实数,整数,定义0^0是1
  3. 除法运算是数学意义的除法,运算结果为浮点数
  4. 整数运算可以用于实数和整数
  5. 取余运算可以用于实数和整数

逻辑运算

  1. and or not 与或非
  2. and和or具有惰性求值或者叫逻辑短路的特点
>>> 5<8 or 3/0
True
>>> 5<8 and 3/0
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    5<8 and 3/0
ZeroDivisionError: division by zero
>>> 5>8 or 3/0
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    5>8 or 3/0
ZeroDivisionError: division by zero
>>> 5<8 and 3/0
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    5<8 and 3/0
ZeroDivisionError: division by zero
>>> 5>8 and 3/0
False
>>> 
复制代码
  1. and和or并不一定返回True或者False,而是得到被计算的表达式的值,运算符not一定会返回True或者False。
>>> 5 and 8
8
>>> 5 or 8
5
>>> not 0
True
>>> 
复制代码

比较运算符

增强赋值运算符