Nurdaulet Kenges Nurdaulet Kenges - 1 year ago 66
Java Question

How to convert expression "<<=1" in Java to Python

In the code below:

for (int N = 2; N <= 128; N <<= 1) {print(N)}

It will print: 2,4,8,16,32,64,128

How can I create such loop in Python? So how I could express "<<=1" in Python?

Answer Source

This for-loop has to be converted into a while-loop:

n = 2
while n <= 128:
    print n
    n <<= 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download