Consider the following:
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 items?
items
The len() function can be used with several different types in Python - both built-in types and library types. For example:
len()
>>> len([1,2,3]) 3
Official 2.x documentation is here: len() Official 3.x documentation is here: len()
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?
For example, if passed the following: a = [] How do I check to see if a is empty?
What's the difference between the list methods append() and extend()?