• <legend id='LidjU'><style id='LidjU'><dir id='LidjU'><q id='LidjU'></q></dir></style></legend>

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

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

        在范围函数内更改步长值?

        时间:2023-11-08
        <legend id='aHnN7'><style id='aHnN7'><dir id='aHnN7'><q id='aHnN7'></q></dir></style></legend>

            • <small id='aHnN7'></small><noframes id='aHnN7'>

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

                  <bdo id='aHnN7'></bdo><ul id='aHnN7'></ul>
                  <tfoot id='aHnN7'></tfoot>
                    <tbody id='aHnN7'></tbody>
                • 本文介绍了在范围函数内更改步长值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  list1 = [1, 2, 3, 4]
                  

                  我正在尝试找出一种方法来更改每个打印 i 的步长值

                  i'm trying to figure out a way to change the step value for each printed i

                  我尝试过的

                  r = 0
                  for i in range(0, 10, list1[r]):
                      print i
                      r = r + 1
                  

                  推荐答案

                  我建议使用 while 循环来实现你自己的生成器.示例 -

                  I would suggest implementing a generator of your own for this using while loop. Example -

                  def varied_step_range(start,stop,stepiter):
                      step = iter(stepiter)
                      while start < stop:
                          yield start
                          start += next(step)
                  

                  那么你可以把它当成——

                  Then you can use this as -

                  for i in varied_step_range(start,stop,steplist):
                      #Do your logic.
                  

                  我们执行 step = iter(stepiter) 以便 stepiter 可以是任何类型的可迭代对象.

                  We do the step = iter(stepiter)so that stepiter can be any kind of iterable.

                  演示 -

                  >>> def varied_step_range(start,stop,stepiter):
                  ...     step = iter(stepiter)
                  ...     while start < stop:
                  ...         yield start
                  ...         start += next(step)
                  ... 
                  >>> for i in varied_step_range(0,10,[1,2,3,4]):
                  ...     print i
                  ... 
                  0
                  1
                  3
                  6
                  

                  这篇关于在范围函数内更改步长值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:通过使用一系列角度python创建一个圆形列表 下一篇:For 循环遍历 2 的幂

                  相关文章

                      <bdo id='ttc4Z'></bdo><ul id='ttc4Z'></ul>

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

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

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