运算符
算术运算符: 加 +, 减 -, 乘 *, 除 /, 取余 %, 取商 //, 幂 **
print(1 + 1)
print(2 - 1)
print(2 * 2)
print(4 / 2)
print(7 % 2)
print(7 // 2)
print(2 ** 3)
赋值运算符: =, +=, -=, *=, /=, %=, //=, **= x = x + y ==> x += y
var_name = 2
another_var = 3
# var_name = var_name + another_var
var_name += another_var
print(var_name)
var_name -= another_var
print(var_name)
var_name **= another_var
print(var_name)
比较运算符:比较最后的结果是什么?True 或者 False 大于: > greater than => gt 小于: < less than => lt 大于等于 :>= greater than equal => ge 小于等于 :<= less than equal => le 等于等于 : == equal => eq 不等于 ? : != not equal => ne
print(2 > 3)
print(3 >= 4)
print(3 <= 4)
print(3 != 4)
逻辑运算符: and or not 用来判断条件的 与 ?condition1 and condition2 ? ? True and True => True ? ? True and False => False ? ? False and False => False ? ? 最少满足两个条件才为真 或 ?condition1 or condition2 ? ? True or True => True ? ? True or False => True ? ? False or False => False ? ? 最少满足一个条件才为真 非 ?not condition ? ? not True -》 False ? ? not False -> True
print(10 & 10)
print(10 | 10)
print(~10)
print(bin(-11))
位运算符: 10 =》1010 => 从右到左, 从低位到高位 ???????????=> 0 * 2^0 + 1 * 2^1 + 0 * 2^2 + 1 * 2^3 ???????????=> 0 + 2 + 0 + 8 ???????????=> 10 10 = 2^1 + 2^3 = > 1010 2^x + 2^y + 2^z .... = 十进制数 1010 => 10 1010 => 10 => &1010 => |1010 1010 -> 取反 ->0101 => 与: & ?1 & 1 = 1, 1 & 0 = 0, 0 & 0 = 0 或: | ?1 | 1 = 1. 1 | 0 = 1, 0 | 0 = 0 取反: ~ 异或: 1 ^ 1 = 0, 1 ^ 0 = 1, 0 ^ 0 = 0 正数的原码,补码和反码: 一样的, 负数:在计算机中用补码表示 ?????原码->补码: ????????原码->取反之后-》反码 ???????反码+1->补码 1010 => 0101 => 1010 + 1 => 1011 0b1010 => -0b0101 => -0b1010 => -0b1011 -0b1011 异或 1011, 1010, 0001 左移: << 0010 << 1000 => 0010 => 10(后边补零)=> 1000 => 1110 >> 0011 -> 3
print(11 ^ 10)
print(2 ** 3)
print(2 << 2)
print(14 >> 2)
身份运算符: 最终结果是True or False is ?xxx is xx is not xxx is not xx
var_data = None
var_data is None
var_data is not None
成员运算符: in, not in
list_data = [1, 2, 3, 4, 5]
print(1 in list_data)
print(6 not in list_data)
|