Do python’s variable length arguments (*args) expand a generator at function call time?

The generator is expanded at the time of the function call, as you can easily check:

def f(*args):
    print(args)
foo = ['foo', 'bar', 'baz']
gen = (f for f in foo)
f(*gen)

will print

('foo', 'bar', 'baz')

Leave a Comment