Latest web development tutorials

Python comprend des exercices 53

Python 100 Li Python 100 Li

Sujet: Apprenez à utiliser Bitwise XOR ^.

Analyse du programme: 0 ^ 0 = 0; 0 ^ 1 = 1; 1 ^ 0 = 1; 1 ^ 1 = 0

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    a = 077
    b = a ^ 3
    print 'The a ^ 3 = %d' % b
    b ^= 7
    print 'The a ^ b = %d' % b

L'exemple ci-dessus sortie est:

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

Python 100 Li Python 100 Li