Confusion and operator

I get the following output with the and operator

code

 >>>0 and [] 0 >>>[] and 0 [] >>> 0 and '' 0 >>>'' and 0 '' 

I could not understand on what basis I get a different result based on the placement of elements.

+1
source share
1 answer

From documents to and :

The expression x and y first evaluates x; if x is false, its value is returned equally; otherwise, y is calculated, and the resulting value is equal returned.

In your case, since 0 , '' and [] all evaluated as False , the first value in each of your expressions is returned.

+2
source

Source: https://habr.com/ru/post/988032/


All Articles