简体   繁体   中英

How to fix syntax error in python around elif?

I cannot understand this syntax error in python.

#I typed this...
elif self.x > 0:
    if self.y != 0:
            self.game.canvas.itemconfig(self.image, \
                                        image=self.images_right[2])

when this code is typed, I get...

Traceback (most recent call back):
    File "<pyshell#12>",line 245, in <module>
        elif self.x > 0:
SyntaxError: invalid syntax

I indented in various ways, but that does not fix it.

elif only works if you have the appropriate if before, eg:

if self.x < 0:
    pass
elif self.x > 0:
   ...

Seems like you miss the if here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM