what is difference between (**) and (<<) in python?

Harshit picture Harshit · Nov 9, 2013 · Viewed 7.6k times · Source
a = 100000000
c = (2**(a-1))-1
b = (2<<(a-1))-1
m = 1000000007
print b%m
print c%m

Output :

494499947
247249973

I am using ** and << operator in python to find powers of 2 raised to a very large number . However similar operations give different result. Just curious why?

Answer

NPE picture NPE · Nov 9, 2013

The results are different because the equivalent of 2 ** n is 1 << n, not 2 << n.