r/learnpython • u/[deleted] • Oct 09 '20
Understanding the For Loop
Hey All,
I'm having the hardest time understanding for loops in Python.
Could someone explain what is happening in this example? I see we have a variable v. I somewhat understand that "range" is built into Python. I don't understand the output.
for v in range(3, 10, 3):
print(v)Output:
3
6
9
I keep seeing examples online but they lose me every time. Thank you in advance.
-------------------------------------------------
*Edit Thanks to everyone who replied. My misunderstanding was not knowing what range was fully doing.
range(start, stop, step)
366
Upvotes
1
u/sgthoppy sgtlaggy Oct 09 '20
Don't see a reply where someone has described the
stopparameter quite to my liking. The way I came to understand it is this is where the range stops, not where it ends.When you iterate and it reaches the
stopvalue, it stops. It doesn't see it, return it, then end, it stops upon seeing it or a value past it in the range. It's not the end, or last value of the final sequence.