Python 如何在离开for循环时获得StopIteration值

Python 如何在离开for循环时获得StopIteration值,python,for-else,stopiteration,Python,For Else,Stopiteration,我看到Python 3中有两个新特性: StopIteration可以通过return语句指定一个值 for循环有else部分,当StopIteration发生时执行该部分 似乎能够在else子句中使用StopIteration.value是合理的,但我找不到它的任何引用。我认为您无法在else子句中获得有关StopIteration的信息。我认为您无法在else子句中获得有关StopIteration的信息。

我看到Python 3中有两个新特性:

  • StopIteration
    可以通过
    return
    语句指定一个值

  • for
    循环有
    else
    部分,当
    StopIteration
    发生时执行该部分


似乎能够在
else
子句中使用
StopIteration.value
是合理的,但我找不到它的任何引用。

我认为您无法在else子句中获得有关
StopIteration
的信息。我认为您无法在else子句中获得有关
StopIteration
的信息。