How do you display a number of items in a list in Python?
Experience Level: Junior
Tags: Python
Answer
To get a number of items in a list, use len().
Example:
items = list["red", "amber", "green"]
number_of_items = len(items)
print(number_of_items)
Related Python job interview questions
How do you delete an item from a list in Python?
Python JuniorHow do you add a new item to a list in Python?
Python JuniorWhat is a private method in Python?
Python JuniorWhy would you use a private method in Python?
Python JuniorHow do you pass an argument to a class constructor in Python?
Python Junior