python -c 'for i in range(10): print i'
works, and
python -c 'a=3;'
works, but
python -c 'a=3;for i in range(10): print i'
gave an error
File "<string>", line 1
a=3;for i in range(10): print i
^
SyntaxError: invalid syntax
Could anyone help point out why? Thank you.
Because that's how Python syntax works. for, like all other statements that introduce an indent level, does not like having anything in front of it.
You need a newline in this case, not a semicolon. These are legal (assuming bash):
python -c 'a=3
for i in range(10)]: print(i)'
python -c $'a=3\nfor i in range(10): print(i)'
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