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

Python Exercise Example 51

Python Exercise Example 51

Python 100 Examples Python 100 Examples

**Problem:** Learn to use the bitwise AND &.

**Program Analysis:** 0&0=0; 0&1=0; 1&0=0; 1&1=1.

Example (Python 2.0+)

#!/usr/bin/python

-- coding: UTF-8 --

if

name

==

'

main

'

:

a

=

0

x77

b

=

a

&

3

print

(

'

a & b = %d

'

%

b

)

b

&=

7

print

(

'

a & b = %d

'

%

b

)

The output of the above example is:


a & b = 3
a & b = 3

Python 100 Examples Python 100 Examples