Does Python programming language have a ternary conditional operator?
Read Time:26 Second

Does Python programming language have a ternary conditional operator?

0 0

Short Answer

Yes, there is. This is how you do it in python

output = "true" if conditon_to_be_statisfied else "false"

Long Answer

If condition_to_be_statisfied result is valid, then the value of the variable output will be anything on the left of the reserved word if. If the contion_to_be_statisfied result is invalid, then the value of the variable output will be anything right of the reserved word else.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *