Python Practice Example 51
Question:Learn to use 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 = 0x77
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 = 3Other extensions
Python 100 Examples