Best way to check that you are at the beginning (the end) of an iterable?

Chris Angelico rosuav at gmail.com
Fri Sep 9 13:30:03 CEST 2011


On Fri, Sep 9, 2011 at 9:04 PM, Peter Otten <__peter__ at web.de> wrote:
>>>> [x] = ""
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ValueError: need more than 0 values to unpack
>>>> [x] = "a"
>>>> [x] = "ab"
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ValueError: too many values to unpack
>

Hey look, it's a new operator - the "assign-sole-result-of-iterable" operator!

x ,= "a"

:)

ChrisA



More information about the Python-list mailing list