Latest web development tutorials

Python incluye ejercicios 51

Python 100 Li Python 100 Li

Tema: Aprender a utilizar a nivel de bits y y.

Programa de análisis: 0 y 0 = 0; 0 & 1 = 0; 1 y 0 = 0; 1 & 1 = 1.

Código fuente:

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

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

La salida del ejemplo anterior es:

a & b = 3
a & b = 3

Python 100 Li Python 100 Li