Python Exercise Example 51
**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
(
'
a & b = %d
'
%
b
)
b
&=
7
(
'
a & b = %d
'
%
b
)
The output of the above example is:
a & b = 3
a & b = 3
Python 100 Examples