-2

I want to assign a variable when if statement is true. What's wrong with this assignment?

b = 1 if 3 > 2

File "<stdin>", line 1
    b = 1 if 3 > 2
                 ^
SyntaxError: invalid syntax
JasmineOT
  • 1,790
  • 2
  • 16
  • 30

1 Answers1

1

You need an else in case your condition fails.

b = 1 if 3>2 else 0
dfundako
  • 7,178
  • 3
  • 14
  • 30