【发布时间】:2016-03-22 07:31:55
【问题描述】:
# why is the following invalid
x = (k, v for k, v in some_dict.items())
# but if we wrap the expression part in parentheses it works
x = ((k, v) for k, v in some_dict.items())
我浏览了文档,似乎没有找到任何关于此的内容?什么可能会混淆语法不允许的解析器?尽管有更复杂的工作:
# k, v somehow confuses the parser but this doesnt???
x = ('%s:%s:%s' % (k, v, k) for k, v in some_dict.items())
那为什么我们不需要用周围的括号包裹%s:%s:%s % (k, v, k)?
【问题讨论】:
标签: python python-3.x syntax generator