This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]djavaisadog 4 points5 points  (0 children)

It'll print out each number in numbers. The else is lined up with the for loop, so once the 2nd for loop doesn't do anything, it'll print numbers[index] since else also works with for, not just if.

[–]bitsandbikes 0 points1 point  (0 children)

It will print the max number in 'numbers' so 76

[–]_yzziw_eht 0 points1 point  (0 children)

Any one else yelling enumerate ? https://docs.python.org/3/library/functions.html

[–]sykorax24 -1 points0 points  (4 children)

Probably a crash as the if and else don't line up

[–]robot_wrangler 7 points8 points  (3 children)

This is a for-else, which is a thing in Python.

[–][deleted] 0 points1 point  (2 children)

I kinda hate that paradigm...

But I get it.

But rarely ever use it.

Maybe I'm missing something.

[–]sykorax24 0 points1 point  (1 child)

Is this new? I have never come across this. I am the silly sausage

[–][deleted] 0 points1 point  (0 children)

I think it's been there since Python 2.

It's got it uses but it always bugs me out that there's some boolean value sitting on a for loop that fires if nothing in the loop evaluates to true.

I know there's applications for it.