3.python3 數據運算

一、數據運算 

算數運算:

比較運算:

賦值運算:

邏輯運算:

成員運算:

身份運算:

位運算:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
  
= 60            # 60 = 0011 1100
= 13            # 13 = 0000 1101
= 0
  
= a & b;        # 12 = 0000 1100
print "Line 1 - Value of c is ", c
  
= a | b;        # 61 = 0011 1101
print "Line 2 - Value of c is ", c
  
= a ^ b;        # 49 = 0011 0001 #相同爲0,不同爲1
print "Line 3 - Value of c is ", c
  
= ~a;           # -61 = 1100 0011
print "Line 4 - Value of c is ", c
  
= a << 2;       # 240 = 1111 0000
print "Line 5 - Value of c is ", c
  
= a >> 2;       # 15 = 0000 1111
print "Line 6 - Value of c is ", c

*按位取反運算規則(按位取反再加1)   詳解http://blog.csdn.net/wenxinwukui234/article/details/42119265

 

運算符優先級:

更多內容:猛擊這裏


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章