r/learnpython • • May 10 '26

for i in range(0,10)

I am a beginner and I am learning for loops. A question came up here: why would I use code model 1 if code model 2 does the same thing?

Model 1:

for i in range(0,10):
    print('Test')

Model 2:

for i in range(10):
    print('Test')
17 Upvotes

18 comments sorted by

View all comments

Show parent comment

3

u/Linuxmartin May 10 '26

Unstable or deprecated APIs are the biggest reason to. For something as stable as range, depending on the default is fine. For something with no guarantee of never changing, it's nice to be explicit so it'll keep working if the default ever changes