0

Why this boolean operation produces a bool:

False and "False" => False

whereas this one produces a str?

False or "Value" => "Value"
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • 2
    Take a look at [this](https://docs.python.org/3/reference/expressions.html#boolean-operations) – shree.pat18 May 05 '22 at 06:03
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 05 '22 at 11:40

1 Answers1

0

False and "anything" will always result in a boolean False.

When you do False or "anything", the "anything" is considered as boolean True as long as it is not False or equivalent to False (like 0, 0.0, etc), and since 'False or True' is equal to true, it returns True or in your case, the string "anything" equivalent to True.

Eshaan Gupta
  • 614
  • 8
  • 25
  • 2
    This doesn't answer why the _boolean_ operation `or` returns a _non-boolean_ value. The correct answer is that `and` returns the _first non-truthy_ operand (or the last operand if they are all truthy), while `or` returns the _last truthy operand_ (or the last operand if they are all falsy) – Pranav Hosangadi May 05 '22 at 17:22
  • 1
    @PranavHosangadi has a nice addition. But the last statement should be updated. Specifically: or returns the **first** truthy operand – Amin.A Aug 12 '23 at 10:42