数据运算-Day1
一、数据运算
1、算数运算符
以下假设变量:a=10,b=20:

2、比较运算符

3、赋值运算符

4、逻辑运算符
以下假设变量a为10,b为20

5、成员运算符

6、身份运算符
身份运算符用于比较两个对象的存储单元

7、位运算符
以下变量a为60,b为13

a = 60 # 60 = 0011 1100
b = 13 # 13 = 0000 1101
c = 0
c = a & b # 12 = 0000 1100
print("Line 1 - Value of c is ",c)
c = a | b # 61 = 0011 1101
print("Line 2 - Value of c is ", c)
c = a ^ b # 49 = 0011 0001 #相同为0,不同为1
print("Line 3 - Value of c is ", c)
c = ~a # -61 = 1100 0011
print("Line 4 - Value of c is ", c)
c = a << 2 # 240 = 1111 0000
print("Line 5 - Value of c is ", c)
c = a >> 2 # 15 = 0000 1111
print("Line 6 - Value of c is ", c)
#返回值:
Line 1 - Value of c is 12
Line 2 - Value of c is 61
Line 3 - Value of c is 49
Line 4 - Value of c is -61
Line 5 - Value of c is 240
Line 6 - Value of c is 15
8、运算符优先级
下面列出了从最高到最低优先级的所有运算符:


浙公网安备 33010602011771号