0

I have to set the value of exp_valu if the value of val1 is 1. I tried to this using the below code, but somehow it is failing. Where am I making mistake?

val1=1
val2=0

exp_valu = if val1: 1 else: 2
print(exp_valu)
Bogota
  • 401
  • 4
  • 15

1 Answers1

1

You can try
exp_valu= 1 if val1 == 1 else 2
In line if statmet not excpecting to have: in it.
The one line if statment look like

value if condition else vale
Leo Arad
  • 4,452
  • 2
  • 6
  • 17