August 2024
Intermediate to advanced
256 pages
5h 34m
English
A for loop is a control flow statement that allows you to iterate over a sequence (such as a list, tuple, string, or range) or any object that is iterable.

It is commonly used when you know the number of iterations in advance or when you want to iterate over the elements of a sequence.
Lets take a look at an example
fruits = [“apple”, “banana”, “cherry”]
for fruit in fruits:
print(fruit)
In this example, the for loop iterates over the fruits list, assigning each element to the fruit variable in each iteration. The print(fruit) statement within the loop prints each fruit to the console.
Read now
Unlock full access