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

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

问题描述

我对遇到的错误感到困惑.

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“如果"语句语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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