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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,130评论 0 23
  • 前几天无事,翻出空间里的大宝孕期日记,念给大宝听,没想到这家伙特别喜欢,一连让我读了三四遍。 特别是讲到怀孕后期,...
    余歌子_柯柯阅读 198评论 0 0
  • 六年级,那曾经看似还很遥远的日子,已经悄然走近。这五年的年华里,曾经说过多少次再见。上个学期,我最好的朋友之一叶...
    信望爱厦门阅读 408评论 4 0
  • 文/刘彩霞 绝望如此泛滥 善良被遮蔽双眼 头上阳光灿烂 幸福在幸福中缠绵 绝望被绝望嚼烂
    彩霞漫天阅读 184评论 0 0
  • 我们都有勇气去鼓励别人追求爱情,但是自己却是个胆小鬼。我们都知道鼓励别人追求爱情,是一个毫不费力的事,因为 结果...
    愿尔懂吾心阅读 376评论 0 2