On Wed, 09 Sep 2009 22:00:41 -0700, s7v7nislands wrote:

> When a negative index is passed as the second or third parameter to the
> index() method, the list length is added, as for slice indices. I don't
> understand the mean.  the list length is added, why? if it changed, the
> original will change ?
...
> I want a example, maybe: use the a negative index is passed as the
> second or third parameter, and see the length changed.


Passing a negative parameter doesn't change the list. Why don't you try 
it for yourself and see?

>>> alist = 'a b c a b c a b'.split()
>>> alist
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b']
>>> alist.index('a')  # start at the beginning
0
>>> alist.index('a', 1)  # start 1 from the beginning
3
>>> alist.index('a', 5)  # start 5 from the beginning
6
>>> alist.index('a', 8-3)  # start 3 from the end
6
>>> alist.index('a', -3)  # start 3 from the end
6
>>> alist  # alist is unchanged
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b']




-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to