Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 52

Python Exercise Example 52

Python 100 Examples Python 100 Examples

**Problem:** Learn to use the bitwise OR |.

**Program Analysis:** 0|0=0; 0|1=1; 1|0=1; 1|1=1

Example (Python 2.0+)

#!/usr/bin/python

-- coding: UTF-8 --

if

name

==

'

main

'

:

a

=

0

o77

b

=

a

|

3

print

(

'

a | b is %d

'

%

b

)

b

|=

7

print

(

'

a | b is %d

'

%

b

)

The output of the above example is:


a | b is 63
a | b is 63

Python 100 Examples Python 100 Examples