, asked
Views : 2

What is basic syntax of Python for Loops?

What is basic syntax of Python for Loops?                                           

1 Answer
Malhar Lathkar

Python's for loop executes the body of loop for each object in a collection such as string, list, tuple or dictionary. Its usage is as follows:

for obj in seq:
    stmt1
    stmt2

Following code snippet iterates over each number element of the list and prints its square

L1=[1,2,3,4,5]
for x in L1:
    print (x*x)

The output will be

1
4
9
16
25

Advertisements
Related Questions