list.reverse()

Mark Bryan Yu vafada at gmail.com
Mon Apr 28 14:12:44 EDT 2008


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

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)?



More information about the Python-list mailing list