y2k y2k - 3 years ago 165
Python Question

How to get the size of a list in Python?

items = []
items.append("apple")
items.append("orange")
items.append("banana")

# FAKE METHOD::
items.amount() # Should return 3


How do I get the number of elements in the list?

Answer Source

The len() function can be used with a lot of types in Python - both built-in types and library types.

>>> len([1,2,3])
3
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download