1

I'm running a small snippet using python -c string statement, but don't seem to get the syntax right when I' using a for loop and defining variables. Help appreciated.

This works:

python -c "for i in (1,2,3):    print(i)"

A simple definition prior to the loop errors:

python -c "a = 123; for i in (1,2,3):    print(i)"
> Syntax Error

A simple definition after the loop works:

python -c "for i in (1,2,3):    print(i); a = 123"
user1767754
  • 23,311
  • 18
  • 141
  • 164

0 Answers0