Difference between revisions of "For loop in Python"

From Interaction Station Wiki
Jump to navigation Jump to search
(Created page with "------------------- source: https://www.w3schools.com/python/python_for_loops.asp")
 
Line 1: Line 1:
 +
 +
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
 +
 +
This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.
 +
 +
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
 +
 +
<syntaxhighlight lang="Python">
 +
 
-------------------
 
-------------------
 
source: https://www.w3schools.com/python/python_for_loops.asp
 
source: https://www.w3schools.com/python/python_for_loops.asp

Revision as of 14:16, 28 August 2024

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.

With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

<syntaxhighlight lang="Python">


source: https://www.w3schools.com/python/python_for_loops.asp