8.5. for Statement

The other looping mechanism in Python comes to us in the form of the for statement. Unlike the traditional conditional looping for statement found in mainstream third-generation languages (3GLs) like C, Fortran, or Pascal, Python's for is more akin to a scripting language's iterative foreach loop.

8.5.1. General Syntax

Iterative loops index through individual elements of a set and terminate when all the items are exhausted. Python's for statement iterates only through sequences, as indicated in the general syntax here:

							for
							iter_var in sequence:
							suite_to_repeat
						

The sequence sequence will be iterated over, and with each loop, the iter_var iteration variable is set to the current element of the sequence, presumably for use ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.