Latest web development tutorials

Python 練習實例52

Python 100例 Python 100例

題目:學習使用按位或| 。

程序分析: 0|0=0; 0|1=1; 1|0=1; 1|1=1

程序源代碼:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    a = 077
    b = a | 3
    print 'a | b is %d' % b
    b |= 7
    print 'a | b is %d' % b

以上實例輸出結果為:

a | b is 63
a | b is 63

Python 100例 Python 100例