Hello,
I'm Francis, a beginner programmer from Ghana, West Africa.
I was wondering why the list .index() method doesn't return negative
indices as well as well as positive indices.
Although ambiguity will make it difficult to implement, in certain cases,
it would be useful if it could return the negative index.
For instance, if one creates an if statement that checks whether an element
is the last item in a list as follows:
listy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
if listy.index(10) == -1:
              print("Monty Python")
I understand that the same effect can be achieved with the index notation -
as in
if listy[-1] == 10:
    print("Monty Python")
- but the way that came naturally to me was to use the .index method rather
than index notation, and it took a very long time for me to figure out why
my code was not working(mostly because I'm a beginner).
So do what you will, I guess.:)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WFYONZWAJ44JDM2FONFPNGUZQTZJZ54E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to