list.reverse()

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Apr 29 04:55:13 EDT 2008


Mark Bryan Yu a écrit :
> This set of codes works:
> 
>>>> x = range(5)
>>>> x.reverse()
>>>> x
> [4, 3, 2, 1, 0]
> 
> But this doesn't:
> 
>>>> x = range(5).reverse()
>>>> print x
> None

This works just as expected - at least for anyone having read the doc.

> Please explain this behavior. range(5) returns a list from 0 to 4 and
> reverse just reverses the items on the list that is returned by
> range(5). Why is x None (null)?

Because that's what list.reverse() returns. Call it a wart if you want 
(FWIW, I do), but at least that's well documented.



More information about the Python-list mailing list