Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature?

Ian Kelly ian.g.kelly at gmail.com
Thu May 3 15:03:25 EDT 2012


On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper <yanegomi at gmail.com> wrote:
>    I was wondering whether this was a parser bug or feature (seems
> like a bug, in particular because it implicitly encourages bad syntax,
> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't
> seem to explicitly require a space between 'in' and another parser
> token (reserved work, expression, operand, etc), but I could be
> misreading the documentation.

The grammar doesn't require whitespace there.  It tends to be flexible
about whitespace wherever it's not necessary to resolve ambiguity.

>>> x = [3, 2, 1]
>>> x [0]if x [1]else x [2]
3
>>> 1 . real
1
>>> 1.5.real
1.5



More information about the Python-list mailing list