-1

I have a very basic snippet of code.

print("a" or "b")
>> a

I'm not entirely sure what I expected to happen. Why does this print "a", and in general how are strings handled with python control flow?

relot
  • 651
  • 1
  • 6
  • 18
  • 1
    Does this answer your question? [How do boolean operators work on strings in python](https://stackoverflow.com/questions/16889732/how-does-boolean-operator-work-on-string-in-python) –  Nov 10 '20 at 08:49

1 Answers1

1

In python, empty strings evaluate to False in a boolean context, while non-empty strings are True.

Alex Hall
  • 34,833
  • 5
  • 57
  • 89
Serial Lazer
  • 1,667
  • 1
  • 7
  • 15