Provide explanation about Iterations (python). Give examples and write a program.
When a statement or any term is executed again and again then it's known as an iteration of the statement. And in python, there are various iterative methods which can be used for example:
1. for loop
suppose there is a list of array
a = [1,2,3,7,8]
so it prints the array in the order of
1
2
3
7
8
code for the same would be:
a = [1,2,3,7,8]
for i in arr:
print((i))
2. while loop
Another most wildly used loop is while loop
for example, if you want to print an integer up to a limit then you can do as follows
i = 7
while i < 34:
print(i)
i += 1
the output will be as follows:
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
For more detailed view of the iterations you can refer to the python documentation online.
Get Answers For Free
Most questions answered within 1 hours.