Python Code Example: length of a list

The length of a list is determined in Python with the len() function.

Code Explanation

LineDescription
1Declaration and initialization of the list myList with the values 1, 2, 3, 4 and 5
3The len() function returns the length of myList.
myList = [1, 2, 3, 4, 5]

print(len(myList))
Output
5