Hello,

I'm fairly new to Python and still learning.

Can someone please explain to me in what way the following function
checks if a number is a power of two? Basically, the second line of
code is what I can't really grasp:

def is_power2(num):
        return num != 0 and ((num & (num - 1)) == 0)

Thank you,
Lazar
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to