Python Puzzle #3: Associativity

· by

What is the output of

1 in [] in "a"

and what is the output of

(1 in []) in "a"

or

1 in ([] in "a")

. . . . . . . . . . . . . . . . . . . . . . . . .

Answer

The first expression evaluates to False, because it gets evaluated as (1 in []) and ([] in 'a') (Manual, Source).

The second two expressions are invalid; they throw an error.