[Python] python: when can I unpack a generator? [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    How does it work under the hood? I don't understand the reason for the errors below:

    >>> def f():
    ... yield 1,2
    ... yield 3,4
    ...
    >>> *f()
    File "<stdin>", line 1
    *f()
    ^
    SyntaxError: invalid syntax
    >>> zip(*f())
    [(1, 3), (2, 4)]
    >>> zip(f())
    [((1, 2),), ((3, 4),)]
    >>> *args = *f()
    File "<stdin>", line 1
    *args = *f()
    ^
    SyntaxError: invalid syntax

    Continue reading...

Compartilhe esta Página