Python“if”语句语法错误 [英] Python "if" statement syntax error

查看:290
本文介绍了Python“if”语句语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我得到的错误感到困惑。

I am confused about the error I am getting.

我的代码如下:

result = getString(argument_x)
print result # it returns "PASS"
if result ="PASS"

当我尝试启动它时,它显示最后一行的错误:

When I try to launch it, it shows an error for the last line:

SyntaxError: invalid syntax


推荐答案

许多Python构造,如if,while和for,需要一个终止冒号,并且后面的行必须在同一级别缩进。

Many Python constructs, like if, while, and for, require a terminating colon :, and the lines following must be indented all at the same level.

缩进级别并不重要,因为与条件关联的所有语句必须缩进到同一级别。

The indent level is not as important as all statements associated with the conditional must be indented at the same level.

在你的情况下,你使用的是if语句:

In your case, you were using an if statement:

result = getString(argument_x)
print result # it returns "PASS"
if result == "PASS":
  print("Result equals pass")
#Add any other statements here to be executed as a result
#of result == "PASS"

这篇关于Python“if”语句语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆