-1

I'm trying to condense my code a bit and put if-else statements on single lines. When I try and do this for an if-else statement that includes an in-list statement, I get an error.

temperature = 10 if 'hi' in ['hi','2'] else temperature = 1

  File "<ipython-input-2-af6c452397be>", line 1
    temperature = 10 if 'hi' in ['hi','2'] else temperature = 1
                 ^
SyntaxError: can't assign to conditional expression

1 Answers1

1

This will accomplish what you intend:

temperature = 10 if 'hi' in ('hi', '2') else 1

By the way, the condition 'hi' in ('hi', '2') is always True, what's the point of it?

Óscar López
  • 232,561
  • 37
  • 312
  • 386