Python 3 crumbs tagged with #for-loop

Your for-loop might be missing an else block

Your for-loop might be missing an else block

Aug 30, 2022 by erik

There's a little-known construct in Python that can be quite useful: using else in combination with loops. That's right, for-loops and while-loops can be followed by an else block! Let's look at how you can use the else block in...

else for-loop
Python for-loop using range with start and stop

Python for-loop using range with start and stop

Mar 6, 2022 by erik

We don't always want to start counting at zero, and that's why we can also call range with both a start and stop value. A call to range(2, 5) will return the values 2, 3, and 4....

range for-loop
Python for loop and lists

Python for loop and lists

Jan 16, 2022 by erik

A Python list can contain zero or more objects. It's a frequently used data type in Python programming. In other programming languages, lists are often called arrays. Python does not have arrays, though, only lists. We can loop, or iterate,...

for-loop list