简单if语句的Python语法错误

时间:2013-08-31 17:41:28

标签: python if-statement syntax-error

我的if语句中出现语法错误:

print "Welcome to the English to Pig Latin translator!"

original = raw_input("Please enter a word to be translated: ")
word_length = len(original)

def length_check():
    If (word_length) > 0 : <-- This colon brings up the following error:
        return original


File "python", line 7
    If (word_length) > 0 :
                         ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:5)

If应更改为if。请注意小写i

>>> If True:

SyntaxError: invalid syntax
>>> if True:
        print True


True

您可能需要阅读The Python Doc's entry on Control Flow