faqts : Computers : Programming : Languages : Python : Snippets : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 5 people (100%) answered Yes
Recently 5 of 5 people (100%) answered Yes

Entry

How can I append an item to a list and find out its index?

Feb 14th, 2007 15:40
Laudeci Oliveira, Andrew Donnellan,


The append method says:
   append(...)
       L.append(object) -- append object to end

So, to find the index of the new item you can use len(list)

Ex.

>>> a = ['a']
>>> a.append('b')
>>> print len(a)