On Wed, Oct 14, 2015 at 4:47 PM, ਨਿਹੰਗ ਪੰਜਾਬੀ <[email protected]> wrote:
> 'if (n & 1)' below works but I don't understand why/how. Kindly help. > > ============== > >>> def fn(n): > ... if (n & 1): > ... print "n is odd" > ... else: > ... print "n is even" > ... > >>> fn(5) > n is odd > >>> fn(4) > n is even > > =============== > & is a bitwise operator, so any odd number and 1 will be one (true), and any even number will be zero (false) Any > > Thanks > Ni > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
