DEV Community

Tommi k Vincent
Tommi k Vincent

Posted on

Using for loops with Lists in Python.

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string)in python. For example here Technically, a for loop repeats the code block once for each value in a list or list-like value. For example, if you ran
this code:

for i in range(4):
print(i)
Enter fullscreen mode Exit fullscreen mode
output
0
1
2
3
Enter fullscreen mode Exit fullscreen mode

This is because the return value from range(4) is a list-like value that Python considers similar to [0, 1, 2, 3].

Top comments (0)