If you have only one statement to execute, one for if, and one for else, you can put it all on the same line:
ExampleOne line if else statement:
a = 2
b = 330
print("A") if a > b else print("B")
You can also have multiple else statements on the same line:
ExampleOne line if else statement, with 3 conditions:
a = 330
b = 330
print("A") if a > b else print("=") if a == b else print("B")
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4