Invalid syntax on VERY SIMPLE Python if … else sta

2020-03-25 04:12发布

Can someone explain why I am getting an invalid syntax error from Python's interpretor while formulating this simple if...else statement? I don't add any tabs myself I simply type the text then press enter after typing. When I type an enter after "else:" I get the error. "Else" is highlighted by the interpreter. What's wrong?

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48)
[MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

>>> if 3 > 0:
        print("3 greater than 0")
        else:

SyntaxError: invalid syntax
>>>

7条回答
倾城 Initia
2楼-- · 2020-03-25 04:43

Else needs to be vertically aligned. Identation is playing a key role in Python. I was getting the same syntax error while using else. Make sure you indent your code properly

查看更多
登录 后发表回答