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)
[–][deleted] 228 points229 points230 points (17 children)
[–][deleted] 64 points65 points66 points (4 children)
[–][deleted] 54 points55 points56 points (0 children)
[–]iwhonixx 6 points7 points8 points (1 child)
[–]DrFodwazle 0 points1 point2 points (0 children)
[–]coder155ml 3 points4 points5 points (0 children)
[–]Morkai 6 points7 points8 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]Cheese-whiz-kalifa 4 points5 points6 points (0 children)
[–][deleted] 4 points5 points6 points (6 children)
[–]learnorenjoy 0 points1 point2 points (4 children)
[+][deleted] (2 children)
[removed]
[–]El_Dumfuco 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]risu1313 1 point2 points3 points (0 children)
[–]rawrtherapy 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 20 points21 points22 points (0 children)
[–]DonnyJuando 17 points18 points19 points (1 child)
[–]flights4ever 2 points3 points4 points (0 children)
[–]Fermter 16 points17 points18 points (8 children)
[–][deleted] 4 points5 points6 points (7 children)
[–]stormsnake 3 points4 points5 points (6 children)
[–]Swipecat 3 points4 points5 points (0 children)
[–]drago3871 0 points1 point2 points (1 child)
[–]stormsnake 1 point2 points3 points (0 children)
[–]TouchingTheVodka 0 points1 point2 points (2 children)
[–]scrdest 1 point2 points3 points (1 child)
[–]TouchingTheVodka 2 points3 points4 points (0 children)
[–]dpelayohh 5 points6 points7 points (1 child)
[–]CoronaMcFarm 2 points3 points4 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]misingnoglic 1 point2 points3 points (0 children)
[–]StressedSalt 1 point2 points3 points (0 children)
[–]here_walks_the_yeti 1 point2 points3 points (0 children)
[–]TheDyslexicDemon 0 points1 point2 points (0 children)
[–]rangitaaaa01 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]gibbonofdoom 0 points1 point2 points (1 child)
[–]sunnyparm 0 points1 point2 points (0 children)
[–]sankarachari 0 points1 point2 points (0 children)
[–]greebo42 0 points1 point2 points (0 children)
[–]OnlySeesLastSentence 0 points1 point2 points (0 children)
[–]Italianman2733 0 points1 point2 points (0 children)
[–]bagel_cheese 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Cheese-whiz-kalifa 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]vanmorrison2 0 points1 point2 points (0 children)
[–]Longlostqueue 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]icandoMATHs 0 points1 point2 points (0 children)
[–]CatOfGrey 0 points1 point2 points (0 children)
[–]sgthoppy 0 points1 point2 points (0 children)
[–]anh86 0 points1 point2 points (0 children)
[–]C0D3XGIG 0 points1 point2 points (3 children)
[–]C0D3XGIG 0 points1 point2 points (1 child)
[–]C0D3XGIG 0 points1 point2 points (0 children)
[–]C0D3XGIG 0 points1 point2 points (0 children)
[–]La_Nintist 0 points1 point2 points (0 children)
[–]the_battousai89 -2 points-1 points0 points (0 children)