0

I am confused about the error I am getting.

My code is as below:

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
0

5 Answers 5

9

Comparison for equality is done using the == operator (you're using a single = which is for assignments only). Also, you're missing a colon:

if result == "PASS":
Sign up to request clarification or add additional context in comments.

3 Comments

OMG, just like that!! Thank you, I tried so much times.... So stupid. Thank you, Tim. It helps.
Tim pointed out the error in your code, also please ensure you do not use 'is' keyword for string comparison. Reason is here: stackoverflow.com/questions/2987958/…
Thank, Devsundar. I'll pay attention on that. :-) Have a good day!
5

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.

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"

5 Comments

For whoever marked this answer down, if you would say what you did not like about my answer, I would edit and fix it up.
I guess it may have to do with the fact that your code still throws a SyntaxError. Perhaps also because you're mixing Python 2 and Python 3 syntax (although that's not the cause of the error).
It was meant as an example only, so I'll go edit not to throw an error. Thanks.
if “year” == 2019: genre = 33 is still failing for me :(
"year" is a string. It will always fail being compared to 2019. I'm surprised you're not getting an error trying to compare the two. if year's value is numeric, then if year == 2019: would be a legitimate comparison.
2

You need a colon at the end of the line,this way if result == "PASS":

Comments

2

You missed the colon operator after the if statement.

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

1 Comment

Your answers are more likely to be found useful and upvoted if you format the code properly so it can read easily. You can find help on that here
1

You missed the colon operator after the if statement.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.