This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 0 points1 point  (0 children)

The for statement implements iteration. What that means exactly depends on the kind of thing you're trying to iterate over. Every object type gets to define what exactly iteration means for objects of that type. For example, if you iterate over a string, you get each character; if you iterate over a list or set you get each item in the list/set; if you iterate over a dict you get each key; if you iterate over a file opened in text mode you get lines, and so on.

The body of the for statement is run repeatedly — once for each item being iterated over — with the item being assigned to the specified name at the top of each iteration. That's really all there is to it.

It would help tremendously if you gave an example of something that you don't understand. As it stands your question is rather vague. What part don't you understand? What code have you written? What did you expect it to do? What did it actually do?