To make your lengthy code looks short and easy human understandable you can write IF-ELSE in one line too.
Observe the syntax specified in this example. You can’t re-arrange anything, not even single space! This is ordinary Python if-else statements.
If Else in one line!
Let’s try to put all IF-ELSE statements in ONE LINE without having any issue with the indentation and generates the same result.
Few more examples to understand how you can implement one liner IF-ELSE Statements.
- Set value for variable “b” – IF a=25 then set b=20 ELSE set b=10
- Set value for variable “b” – IF var=”OneLineCode” then set b=20 ELSE set b=10
- Set value for variable “b” – IF var=”not_matching_str” then SET b=”New str” ELSE Set b=”TheEnd”