Do python's variable length arguments (*args) expand a generator at function call time? -
consider following python code:
def f(*args): in args: pass foo = ['foo', 'bar', 'baz'] # python generator expressions ftw gen = (f f in foo) f(*gen)
does *args
automatically expand generator @ call-time? put way, iterating on gen
twice within f(*gen)
, once expand *args
, once iterate on args? or generator preserved in pristine condition, while iteration happens once during loop?
the generator expanded @ time of function call, can check:
def f(*args): print(args) foo = ['foo', 'bar', 'baz'] gen = (f f in foo) f(*gen)
will print
('foo', 'bar', 'baz')
Comments
Post a Comment