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

Python Exercise Example 53

Python Exercise Example 53

Python 100 Examples Python 100 Examples

**Problem:** Learn to use the bitwise XOR ^.

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

Program source code:

Example

#!/usr/bin/python

-- coding: UTF-8 --

if

name

==

'main'

:

    a

=

0o77

    b

=

a ^

3

   

print

(

'The a ^ 3 = %d'

% b

)

    b ^

=

7

   

print

(

'The a ^ b = %d'

% b

)

The output of the above example is:


The a ^ 3 = 60
The a ^ b = 59

Python 100 Examples Python 100 Examples