[Python] The If Banana Else One Liner

It is possible to do a Python if else one liner, and here is an example.

The Full Fat Example

Firstly, here is an example in full format:

fruit = "banana"
if fruit == "banana":
  print("This is a banana!")
else:
  print("This is NOT a banana!")

The One Liner Example

fruit = "banana"; print("This is a banana!") if fruit == "banana" else print("This is NOT a banana!")


Comments