JacksonDavis
JacksonDavis

Reputation: 23

Invalid syntax when using single equals to compare in an if statement

I get a SyntaxError from this code:

if wallDirection = '-X':
    xAxis = -buildingSectionWidth

What is wrong, and how do I fix it?

Upvotes: -1

Views: 766

Answers (1)

Chris Martin
Chris Martin

Reputation: 30736

First see What is the difference between an expression and a statement in Python? An if statement requires an expression as its condition.

wallDirection = '-X' is a statement that assigns wallDirection to the value -X. The expression you likely want here is wallDirection == '-X'. The operator that tests for equality is ==, not =.

if wallDirection == '-X':
    xAxis = -buildingSectionWidth

Upvotes: 1

Related Questions