Use of loops with “for”

I created a Python program with a basic “for” loop.

Loops can be created with while and for making loops with forFor loops are traditionally used when you have a piece of code which you want to repeat n number of times If you’ve done any programming before, there’s no doubt you’ve come across a for loop or an equivalent to it. In Python, they work a little differently. Basically, any object with an iterable method can be used in a for loop in Python. Even strings, despite not having an iterable method – but we’ll not get on to that here. Having an iterable method basically means that the data can be presented in list form, where there’s multiple values in an orderly fashion. You can define your own iterables by creating an object with next() and iter() methods. This means that you’ll rarely be dealing with raw numbers when it comes to for loops in Python – great for just about anyone!.

source: wiki.python.org

CC BY 4.0 Use of loops with “for” by Jorge Padilla is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.