0

In js and other languages I often perform conditional actions with (...) && console.log('Tis True') || console.log('Tis False');, which I like because it's simple and fits on one line.

Is there a one-liner equivalent in python3? Or do I have to break it over several lines with a boring, old if (): ... statement?

Magnus
  • 3,086
  • 2
  • 29
  • 51

1 Answers1

1

You can use and and or in the same way in python:

print("yes") if True else print("no")
# yes

print("yes") if False else print("no")
# no
match
  • 10,388
  • 3
  • 23
  • 41