I am a python newbie and have a question. Why can a if allow a brackets and not for.
if (1==2):
for (i in range(1,10)):
while (i<10):
First one and third one are valid syntax but not second one.
File "<stdin>", line 2
for (i in range(1,10)):
^
Because for (i in range(1,10))
isn't syntactically correct.
Lets assume (i in range(1,10))
was parsed anyway, it would return a boolean. So then you're trying to say for True
or for False
, and booleans can't be iterated, and it's invalid syntax.
The reason why your other examples work is because they expect a boolean, which is what is returned from 1 == 2
and i < 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With