To get the length of a list in Python, you can use the len()
function.
In this example,
numbers
with integer values.len()
function to get the number of elements in the list numbers
.len()
function returns the number of elements in the list.numbers = [1, 2, 3, 4, 5]
length = len(numbers)
print("Length of the list is:", length)
Length of the list is: 5
In this example,
fruits
with string values.len()
function to get the number of elements in the list fruits
.len()
function returns the number of elements in the list.fruits = ["apple", "banana", "cherry"]
length = len(fruits)
print("Length of the list is:", length)
Length of the list is: 3
In this tutorial, we learned How to Get Length of a List in Python language with well detailed examples.