0

I came to know about switch in C++. Right now my trying to learn python. I want the equivalent code of switch in python. I know about else if ladder. I need something more similar to switch

0

The closest you can get is the following:

num = 4
even = True if num % 2 == 0 else False
print(even)  # prints True
num = 5
even = True if num % 2 == 0 else False
print(even)  # prints False

More complete answer: https://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator/394814#394814

Happy Coding!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .