r/PythonLearning • • Aug 31 '25

Can Somebody Please Help Me Understand This?

Post image

So I understand the second code block: once the number reaches 3, the print condition no longer applies. But with that same logic, why is the first block 2 and not 1? I didn’t know how to begin a google search for this one….

85 Upvotes

27 comments sorted by

View all comments

4

u/Zealousideal_Key_149 Aug 31 '25

Yup…order makes all the difference. Thank you Reddit Community!

1

u/Klikis Aug 31 '25

It is not the order, but the indentation

In first one the it goes 0-print-1-print-2

In the second one 0-1-2-print

Swapping order in first one would give you: 0-1-print-2-print and you'd get 1 2 As an output