Why does Python return [15] for [0xfor x in (1, 2, 3)]? [duplicate]
59
When running the following line:
>>> [0xfor x in (1, 2, 3)]
I expected Python to return an error.
Instead, the REPL returns:
[15]
What can possibly be the reason?
python python-3.x operator-precedence short-circuiting
[0xf or x in (1, 2, 3)]
. You've actually found a minor bug in Stack Overflow's syntax highlighter, as it renders the0xfor
without colouring theor
;) – 101 Apr 14 at 0:403or 4
or"hello"and 5
. I suspect it's a consequence to accommodate cases for binary operators such as "3>4", but in the case of comparison ops, it's not a straight connection as you can't do3and5
. I posted in python-dev and see what they say – Stefano Borini Apr 14 at 10:25"hello"and 5
and3>5
are different."
and>
are not valid in identifiers or other forms of expressions. What is unexpected is that a string of pure alphanumeric characters (i.e.[a-z0-9]
) can be interpreted as 2 tokens instead of one "randomly" – GACy20 Apr 14 at 12:40