The following python code prints "no" as it should
for _ in range(10):
a = 5+i
if a > 50:
print ("yes")
print("no")
But so does the following
for _ in range(10):
a = 5+i
if a > 50:
print ("yes")
else:
print("no")
I've never seen an else without an if in other languages, yet here the else seems to line up with the for. How is this possible? Shouldn't Python regard the second version as a syntax error?
I entered something like the second version by accident in a larger script and the script seemed to work. I didn't understand why.