Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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)
exp_valu = 1 if val1 == 1 else 2
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
exp_valu= 1 if val1 == 1 else 2
:
value if condition else vale
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
exp_valu = 1 if val1 == 1 else 2