赋值运算符、逻辑运算符、表达式

赋值运算符:

num += 1 等价于 num = num + 1

num -= 1 等价于 num = num - 1

num *= 2 等价于 num = num * 2

num /= 2 等价于 num = num / 2

num //= 2 等价于 num = num // 2(整除)

num %= 2 等价于 num = num % 2(余数)

num **= 2 等价于 num = num ** 2(指数)

逻辑运算符:and, not, or(将多个条件连接起来)(真值表)

and: 且,并且(只有两个条件全部为True时,结果才会为True)

条件1 and 条件2

5>3 and 6>2

True

or: 或,或者(只要有一个条件为True,结果为True)

5>3 or 6<2

True

not: 

not 5>3

False

not 5<3

True

优先级:not > and > or ,为了方便阅读,加小括号()

表达式:由运算符和操作数组成

猜你喜欢

转载自www.cnblogs.com/evatan123/p/9186107.html