从listcomp或genexpr中产生的差异

时间:2017-07-20 08:25:13

标签: python python-3.x list-comprehension generator-expression yield-from

为什么结果不同?

In [19]: [(yield from (1, 2)) for x in [1]]
Out[19]: <generator object <listcomp> at 0x0438B3C0>

In [20]: list(_)
Out[20]: [1, 2]

In [21]: ((yield from (1, 2)) for x in [1])
Out[21]: <generator object <genexpr> at 0x0438B480>

In [22]: list(_)
Out[22]: [1, 2, None]

0 个答案:

没有答案