+ 1
What is the alternative for *if elif else* ladder in Python?
3 Respuestas
+ 5
There are no strict alternatives for if elif else statements, such as switch statement which I assume you to have been searching for.
+ 5
You can get rid of elif by nesting more if else statements within the else but elif helps reduce the levels of nesting.
+ 3
Depending how complicated your conditions are. You can use a dictionary to drive a condition, where the key is the result of the conditional expression, and the value could even be a function call.
Also you can use map() to transform values.