What is the reason from different output generate using logical 'and' and 'or' operator in Python 3.10.8

David bouncingcats at gmail.com
Mon Nov 7 19:05:50 EST 2022


On Tue, 8 Nov 2022 at 03:08, ICT Ezy <ictezy at gmail.com> wrote:

> Please explain how to generate different output in following logical operations

> >>> 0 and True
> 0
> >>> 0 or True
> True
> >>> 1 and True
> True
> >>> 1 or True
> 1

Hi,

The exact explanation of how 'and' and 'or' behave can be read here:
  https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
The "Notes" there explain what you see.


More information about the Python-list mailing list