美文网首页
list comprehension vs general ex

list comprehension vs general ex

作者: sherrysack | 来源:发表于2017-07-01 23:00 被阅读0次

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 ex

      本文链接:https://www.haomeiwen.com/subject/hxngcxtx.html