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