list comprehension vs general expression

As an expression(in the grammar):

  • [i for i in [1,2,3]] is a list comprehension;
  • (i for i in [1,2,3]) is a general expression;
  • But i for i in [1,2,3] by itself is a syntax error, and that's just the way it is. There must be something surrounding it. Unless you have ( or [ around it, it's not a valid expression, because the for keyword is not valid at that point.

你可能感兴趣的:(list comprehension vs general expression)