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

 Live Demo

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

Output

0 Tutorial 1 point

Zip construct

Example

 Live Demo

# 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

 Live Demo

# 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.

Updated on: 2019-08-29T12:09:14+05:30

267 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements