Python "and" doesn't always return bool

Just open up python and test it yourself, takes around 1 min:

assert ([1,2,3] and [4,5,6]) == [4,5,6]

Occasionally useful (but completely unreadable)

1 Like

image

1 Like

sry, bad example. The == sign will return a bool but and won’t.

print([1,2,3]and[4,5,6])

Ah gotcha. Why does Python pick [4, 5, 6]?

You can read the docs.

The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.
The expression x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.

1 Like