<bdo id='ACjAC'></bdo><ul id='ACjAC'></ul>
  1. <small id='ACjAC'></small><noframes id='ACjAC'>

  2. <i id='ACjAC'><tr id='ACjAC'><dt id='ACjAC'><q id='ACjAC'><span id='ACjAC'><b id='ACjAC'><form id='ACjAC'><ins id='ACjAC'></ins><ul id='ACjAC'></ul><sub id='ACjAC'></sub></form><legend id='ACjAC'></legend><bdo id='ACjAC'><pre id='ACjAC'><center id='ACjAC'></center></pre></bdo></b><th id='ACjAC'></th></span></q></dt></tr></i><div id='ACjAC'><tfoot id='ACjAC'></tfoot><dl id='ACjAC'><fieldset id='ACjAC'></fieldset></dl></div>
    1. <legend id='ACjAC'><style id='ACjAC'><dir id='ACjAC'><q id='ACjAC'></q></dir></style></legend>
      <tfoot id='ACjAC'></tfoot>

      python的可变长度参数(*args)是否在函数调用时扩展生成器?

      Do python#39;s variable length arguments (*args) expand a generator at function call time?(python的可变长度参数(*args)是否在函数调用时扩展生成器?)
    2. <i id='epFS8'><tr id='epFS8'><dt id='epFS8'><q id='epFS8'><span id='epFS8'><b id='epFS8'><form id='epFS8'><ins id='epFS8'></ins><ul id='epFS8'></ul><sub id='epFS8'></sub></form><legend id='epFS8'></legend><bdo id='epFS8'><pre id='epFS8'><center id='epFS8'></center></pre></bdo></b><th id='epFS8'></th></span></q></dt></tr></i><div id='epFS8'><tfoot id='epFS8'></tfoot><dl id='epFS8'><fieldset id='epFS8'></fieldset></dl></div>
            <bdo id='epFS8'></bdo><ul id='epFS8'></ul>

            1. <tfoot id='epFS8'></tfoot>
                  <tbody id='epFS8'></tbody>

              1. <legend id='epFS8'><style id='epFS8'><dir id='epFS8'><q id='epFS8'></q></dir></style></legend>

                <small id='epFS8'></small><noframes id='epFS8'>

                本文介绍了python的可变长度参数(*args)是否在函数调用时扩展生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                考虑以下 Python 代码:

                Consider the following Python code:

                def f(*args):
                    for a in args:
                        pass
                
                foo = ['foo', 'bar', 'baz']
                
                # Python generator expressions FTW
                gen = (f for f in foo)
                
                f(*gen)
                

                *args 会在调用时自动扩展生成器吗?换句话说,我是否在 f(*gen) 内对 gen 进行了两次迭代,一次是展开 *args,一次是对 args 进行迭代?还是生成器保持原始状态,而迭代只在 for 循环中发生一次?

                Does *args automatically expand the generator at call-time? Put another way, am I iterating over gen twice within f(*gen), once to expand *args and once to iterate over args? Or is the generator preserved in pristine condition, while iteration only happens once during the for loop?

                推荐答案

                生成器在函数调用时展开,您可以轻松查看:

                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)
                

                将打印

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

                这篇关于python的可变长度参数(*args)是否在函数调用时扩展生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                  <small id='d0PnY'></small><noframes id='d0PnY'>

                  <i id='d0PnY'><tr id='d0PnY'><dt id='d0PnY'><q id='d0PnY'><span id='d0PnY'><b id='d0PnY'><form id='d0PnY'><ins id='d0PnY'></ins><ul id='d0PnY'></ul><sub id='d0PnY'></sub></form><legend id='d0PnY'></legend><bdo id='d0PnY'><pre id='d0PnY'><center id='d0PnY'></center></pre></bdo></b><th id='d0PnY'></th></span></q></dt></tr></i><div id='d0PnY'><tfoot id='d0PnY'></tfoot><dl id='d0PnY'><fieldset id='d0PnY'></fieldset></dl></div>
                      <tfoot id='d0PnY'></tfoot>
                        <bdo id='d0PnY'></bdo><ul id='d0PnY'></ul>

                          <legend id='d0PnY'><style id='d0PnY'><dir id='d0PnY'><q id='d0PnY'></q></dir></style></legend>
                            <tbody id='d0PnY'></tbody>