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
18
u/DonnyJuando Oct 09 '20
stop me if I say something stupid. your range(3, 10, 3) parameter tells the program where to start, where to stop, and how to step through the range. your range starts at 3 & stops at 10 & steps on every 3rd integer in between. so your output is the low range start, 3; and every 3rd integer up to your upper limit (10), 6 & 9.
range(start, stop, step)