How do I find out how many objects are in a list
basically what the title says. I want to be able to find out how many objects a list contains. Maybe my Google-fu is failing me or my termin开发者_如何学编程ology is wrong.
len(s)
Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).
>>> l = [1, 2, 3]
>>> len(l)
3
Check out the len built-in function:
len(someList)
http://docs.python.org/library/functions.html#len
a = ['1', '2', '3']
print len(a)
This wiil print:
3
精彩评论