I'm trying to create a for
loop and I ran into problems. I don't understand how these loops work, and I think the problem is because I'm using the for
syntax incorrectly.
From what I understand, a for
loop should look like
for w in words:
print(w, len(w))
But how exactly does it work?
To try to be specific: What does the w
mean? How can I know what to write between for
and in
, and after in
? What exactly happens when the code runs?
For a more technical breakdown of how for
loops are implemented, see How does a Python for loop with iterable work?.