To calculate the length of a list in Python, you can use the len()
function.
Here's an example of how to calculate the length of a list:
my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print(length) # Output: 5
In this example, the len()
function returns the number of elements in the list my_list
, and the length is assigned to the length
variable. The value 5
is then printed, indicating that the list has 5 elements.