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
  • 12,464
  • 7
  • 65
  • 73
Zach Gates
  • 4,045
  • 1
  • 27
  • 51

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
  • 842,883
  • 184
  • 1,785
  • 1,677
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,440
  • 2
  • 17
  • 25