Reply To: Python for-Loop

Welcome to Python Land Forums The Python Tutorial Python for-Loop Reply To: Python for-Loop

#2344
Erik van Baaren
Keymaster

OK sorry for the late reply. What you want is a range: https://docs.python.org/3.3/library/stdtypes.html?highlight=range#range

E.g.:

for i in range(1, 11):
    print(i)

This will give the output you are looking for. The range() function is an iterable, more about that can be read here: https://python.land/deep-dives/python-iterator

Alternatively, you can use a list of numbers. Something like for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:.

But the example I gave you used a string, and with the for loop you iterate over the letters. Python sees those as strings, not as numbers.