Invalid Syntax

cs at zip.com.au cs at zip.com.au
Tue Aug 9 19:05:43 EDT 2016


On 09Aug2016 20:22, Rob Gaddi <rgaddi at highlandtechnology.invalid> wrote:
>Ltc Hotspot wrote:
>> What is the source of the following,
>> 'error message: SyntaxError: invalid syntax (<string>, line 2)'
>> v. Python 3.3
>>
>> Code reads:
>>
>> x=1
>> if x==1
>>     # indent 4 spaces
>>     print "x = 1"
>
>A missing colon, the appropriate location of which is left as an
>exercise to the reader.

A bit unfair, it is not the most helpful of syntax complaints. Hal: all Python 
compound statements (if, while, for, with etc) end in a colon and an indented 
"suite" (enclosed chunk of statements). So:

  if x == 1:
      ......

Also, in Python 3 "print" is a function, so:

  print("x = 1")

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list