2-Variable For Loop in Python -
what python equivalent c/c++ code snippet below?
// rest of code. (i = 1, j = 0; < 10, j < 19; ++i, j += 2) { // body of loop. }
you can try this:
for i,j in zip(range(1,10),range(0,19,2)):
you have 2 things understand:
- how range() works
- how zip() works
range takes 3 params. start,end , increment.
first 1 inclusive , second exclusive,3rd increment in c/c++.
range(1,10)
as first 1 inclusive start 1, , 2nd 1 exclusive end @ 9. default increment one.
range(0,19,2)
as wanted, loop start 0 , end @ 18 , increment 2.
Comments
Post a Comment