Course Content
How to Add a Virtual Environment in Python
0/1
Set
0/1
Python
About Lesson

A for loop in Python is a control structure used to iterate over a sequence, such as a list, tuple, or string. It allows you to execute a block of code repeatedly for each item in the sequence. This makes it easy to perform operations on each element without manually specifying the index. The syntax is concise and enhances code readability.

Python
#Syntax
for item in sequence:
    # Code block to execute
Python
#For loops Questions
>>> range(10)
range(0, 10)
>>> x=range(1,10)
>>> x
range(1, 10)
>>> for i in x:
...     print(i)
...
1
2
3
4
5
6
7
8
9
>>> for i in range(2,20,2):
...     print(i)
...
2
4
6
8
10
12
14
16
18