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)
2

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.