1 a = 21
2 b = 10
3 c = 0
4 5 c = a + b
6print ("Line 1 - Value of c is ", c)
7 8 c = a - b
9print ("Line 2 - Value of c is ", c)
1011 c = a * b
12print ("Line 3 - Value of c is ", c)
1314 c = a / b
15print ("Line 4 - Value of c is ", c )
1617 c = a % b
18print ("Line 5 - Value of c is ", c)
1920 a = 2
21 b = 3
22 c = a**b
23print ("Line 6 - Value of c is ", c)
2425 a = 10
26 b = 5
27 c = a//b
28print ("Line 7 - Value of c is ", c)
1#位運(yùn)算符 2 a = 60 # 60 = 0011 1100 3 b = 13 # 13 = 0000 1101 4 c = 0
5 6 c = a & b; # 12 = 0000 1100 7print"Line 1 - Value of c is ", c
8 9 c = a | b; # 61 = 0011 1101 10print"Line 2 - Value of c is ", c
1112 c = a ^ b; # 49 = 0011 000113print"Line 3 - Value of c is ", c
1415 c = ~a; # -61 = 1100 001116print"Line 4 - Value of c is ", c
1718 c = a << 2; # 240 = 1111 000019print"Line 5 - Value of c is ", c
2021 c = a >> 2; # 15 = 0000 111122print"Line 6 - Value of c is ", c
?9.4成員運(yùn)算符 ??(1)in:在指定序列中找到值返回true ??(2)not in
1 a = 10
2 b = 20
3 list = [1, 2, 3, 4, 5 ];
4 5if ( a in list ):
6print ("Line 1 - a is available in the given list")
7else:
8print ("Line 1 - a is not available in the given list")
910if ( b notin list ):
11print ("Line 2 - b is not available in the given list")
12else:
13print ("Line 2 - b is available in the given list")
1415 a = 2
16if ( a in list ):
17print ("Line 3 - a is available in the given list")
18else:
19print ("Line 3 - a is not available in the given lis)t"
1#身份運(yùn)算符 2 a = 20
3 b = 20
4 5if ( a is b ):
6print ("Line 1 - a and b have same identity")
7else:
8print ("Line 1 - a and b do not have same identity")
910if ( id(a) == id(b) ):
11print ("Line 2 - a and b have same identity")
12else:
13print ("Line 2 - a and b do not have same identity")
1415 b = 30
16if ( a is b ):
17print ("Line 3 - a and b have same identity")
18else:
19print ("Line 3 - a and b do not have same identity")
2021if ( a isnot b ):
22print ("Line 4 - a and b do not have same identity")
23else:
24print ("Line 4 - a and b have same identity")