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

后端 未结 3 1280
别那么骄傲
别那么骄傲 2020-12-11 03:50

Consider the following Python code:

def f(*args):
    for a in args:
        pass

foo = [\'foo\', \'bar\', \'baz\']

# Python generator expressions FTW
gen          


        
3条回答
  •  没有蜡笔的小新
    2020-12-11 04:17

    Why not look and see what gen is in f()? Add print args as the first line. If it's still a generator object, it'll tell you. I would expect the argument unpacking to turn it into a tuple.

提交回复
热议问题