Simple question, how do you tell how many items in a list?
WDC
ki4yjl at gmail.com
Fri Jul 11 15:25:45 EDT 2008
On Jul 11, 2:53 pm, Terry Reedy <tjre... at udel.edu> wrote:
> Alex Bryan wrote:
> > I am just wondering how you get an integer value for how many items
> > there are in a list, preferably w/o a for loop.
>
> Read the library reference sections on built-in functions and classes.
Quite simple.
If I understand you correctly, you have a list like this:
>>> list = ['a', 'b', 'c', 'd']
As you can see, the list has 4 entries.
The len() function also says that we have 4 entries.
>>> len(list)
4
Now, if we wanted a particular entry, we would do this:
>>> list[0]
'a'
(Remember, when calling something in a list we count zero.)
>>> list[3]
'd'
Hope this helped.
David
More information about the Python-list
mailing list