Python语法错误(else语句)

Python语法错误(else语句),python,python-2.7,if-statement,Python,Python 2.7,If Statement,当我运行下面的脚本时,它显示 SyntaxError:无效语法 single = True if single = True: print "Hey Girl, can I get your number ? " else print "Bye. !" 只需键入if single:它检查single是否为True并继续执行。如果single为False,它将移动到else语句。另外,你忘了在else语句前面加上 single = True if single: prin

当我运行下面的脚本时,它显示
SyntaxError:无效语法

single = True    

if single = True:
 print "Hey Girl, can I get your number ? "
else
 print "Bye. !"

只需键入if single:它检查single是否为True并继续执行。如果single为False,它将移动到else语句。另外,你忘了在else语句前面加上

single = True

if single:
    print ("Hey Girl, can I get your number ? ")
else:
    print ("Bye. !")

您需要确保else分支前面有一个冒号!请记住,Python是非常面向空间的,所以一切都需要保持整洁,以便Python喜欢您

single = True    

#Instead of just doing single-space indenting it would behoove you to use regular tabs
if single == True: #<- Also, also, instead of doing just one equal sign (which is assignment) You should use the equality operator '=='
    print "Hey Girl, can I get your number ? "
else: #<- You were missing a colon here
    print "Bye. !"
single=True
#与其只进行单空格缩进,不如使用常规制表符

如果single==True:#如果single==True:
,则应该是
,如果single:
,则更好的是
。@WillemVanOnsem的anwser不完整。Else语句也有语法错误。@WillemVanOnsem我尝试了“if single==True:”和“if single:”它仍然给我提供了与Python 2相同的语法错误。X@revy:不,真实性在所有版本的python中进行评估…@revy OP也被标记为python 2.7,
如果单个:
使用python,not
为真
/
为假
@revy:你自己的答案也有同样的“问题”。答案的文本中没有提到
print
有问题。问题出在
if
语句(以及
else
语句)。