The Python Game Book

code games. learn Python.

User Tools

Site Tools


Sidebar

Github:

en:glossary:f:for_loop

for loop

In python, you can iterate over an iterable by using a for loop.

Usually, iterating is done over a range object, but you can iterate over every iterable in python, like over the chars inside of a string.

>>>for char in "abcdefg":
       print(char)

a
b
c
d
e
f
g
>>>

changing the iterable while looping over it

It is possible to change the size of a list while iterating over it. However, when iterating over a dict, changing it's size throws an error

en/glossary/f/for_loop.txt · Last modified: 2020/12/19 22:18 by horst