python: when can I unpack a generator?

妖精的绣舞 提交于 2019-12-05 03:42:28

The *iterable syntax is only supported in an argument list of a function call (and in function definitions).

In Python 3.x, you can also use it on the left-hand side of an assignment, like this:

[*args] = [1, 2, 3]

Edit: Note that there are plans to support the remaining generalisations.

Running this in Python 3 gives a more descriptive error message.

>>> *f()
SyntaxError: can use starred expression only as assignment target

The two errors are showing the same thing: you can't use * on the left-hand side of an expression.

I'm not sure what you're expecting to happen in those cases, but it's not valid.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!