Use range to print [100, 1000, 10000]

  • A+
Category:Languages

I have such a list:

for i in [100, 1000, 10000]:     print(i) 

How could I reproduce it with range

for i in range(100, 10000, 100)     print(i) 

the above code does not work as expected.

 


You are printing increasing powers of ten, so you can do this:

>>> for i in range(2, 5): ...     print(pow(10, i)) ...  100 1000 10000 

Edit

As Graham observes in the comments, you can also do

>>> for i in range(2, 5): ...     print(10 ** i) ...  100 1000 10000 

if you prefer the ** notation for exponentiation.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: