0

In my code I have these lines:

if numVotes == 0:
    avId in self.disconnectedAvIds or self.resultsStr += curStr

When I run the code I get this error?

SyntaxError: illegal expression for augmented assignment

How do I fix this error?

Georgy
  • 9,972
  • 7
  • 57
  • 66
Zach Gates
  • 3,905
  • 1
  • 25
  • 48

2 Answers2

3

The assignment

self.resultsStr += curStr

is a statement. Statements can not be part of expressions. Therefore, use an if-statement:

if avId not in self.disconnectedAvIds:
    self.resultsStr += curStr

Python bans assignments inside of expressions because it is thought they frequently lead to bugs. For example,

if x = 0    # banned

is too close too

if x == 0   # allowed
Community
  • 1
  • 1
unutbu
  • 777,569
  • 165
  • 1,697
  • 1,613
1

avId in self.disconnectedAvIds will return a boolean value. or is used to evaluate between two boolean values, so it's correct so far.

self.resultsStr += curStr is an assignment to a variable. An assignment to a variable is of the form lvalue = rvalue where lvalue is a variable you can assign values to and rvalue is some expression that evaluates to the data type of the lvalue. This will not return a boolean value, so the expression is illegal.

If you want to change the value if avId is in self.disconnectedAvIds then use an if statement.

if avId in self.disconnectedAvIds:
    self.resultsStr += curStr
Mdev
  • 2,434
  • 2
  • 16
  • 24