Computer >> Computer tutorials >  >> Programming >> Python

Looping Techniques in Python


In this tutorial, we will learn about looping techniques in python 3.x. Or earlier. There are many ways in which we can implement loops. Here we will be discussing four techniques in looping.

Enumeration construct

Example

# enumerate() type
for index, value in enumerate(['Tutorial','point']):
   print(index, value)

Output

0 Tutorial
1 point

Zip construct

Example

# zip() method
arr1 = ['Tutorial','point']
arr2 = ['python','loops']
for i,j in zip(arr1, arr2):
   print(i,j)

Output

Tutorial python
point loops

Membership construct

Example

# membership operator
for i in ['Tutorial','point']:
   print(i)

Output

Tutorial
point

Infinitive construct

Example

# infinite loop
while(True):
   pass

Step - based construct

Example

# range with step incrementer
For i in range(0,4,2):
   print(i)

Output

0
2

Conclusion

In this article, we learned about Looping Techniques in Python 3.x. Or earlier.