基本运算符
1. 算术运算符
+ - * / % ** //
2. 比较运算符
== != > < >= <=
3. 赋值运算符 =
4. 增量赋值
# 增量赋值
n = 666
n = n + 1 # n += 100
n = n - 1 # n -= 1
n = n * 1 # n *= 1
n = n / 1 # n /= 1
print(n) # 667
5. 链式赋值
x = 10
y = 10
z = 10
print(x, y ,z)
x = y = z = 10
print(x, y, z)
6. 交叉赋值
# 交换m,n的值
# m = n
# n = m
# print(m, n)
# 借助于第三个变量
# temp = m
# m = n
# n = temp
# print(m, n)
m, n = n, m
print(m, n)
7. 解压赋值
# l, l1, l2, l3 = names_list
# l, l1, l2, l3 = ['kevin', 'jack', 'rose', 'tank', ]
# print(l, l1, l2, l3)
# l, *_, l3 = ['kevin', 'jack', 'rose', 'tank', ]
# print(l)
# print(l3)
# '''
# *后面的变量名结束多余的变量值,并且组装成列表的形式返回
# '''
# print(_) # ['jack', 'rose']
# l, *_, last = ['kevin', 'jack', 'rose', 'tank', ]
# print(last)
8. 逻辑运算符
and:与,连接两个条件,它的结果两边必须都是真,结果才是真
>>>: 2 > 1 and 1 != 1 and True and 3 > 2
False
or:或,连接的两个条件,只要有一个是真,结果就是真
>>>:2 > 1 or 1 != 1 or True or 3 > 2
True
not:非,取反
>>>: (3>4 and 4>3) or (1==3 and 'x' == 'x') or 3 >3
True
not True--->False
# 优先级not>and>or