#a list
cars = ['Ford', 'Volvo', 'BMW', 'Tesla']
#some updates on list
cars.append('Honda')
cars.append('Tata')
#find length of list
length = len(cars)
print('Length of the list is :', length)
6
#get length of list in Python using for loop
List = [‘Python’,’Java’,’Kotlin’,’Machine Learning’,’Keras’]
size = 0
print(“Length of the input string:”)
for x in List:
size+=1
print(size)
Output:
Length of the input string:
5
# It doesn't matter what is the type of the item
# It will count the number of items in the list
x = [1, 2, 5.67, 2.45, 'John', 'Pat', True, False]
length = len(x) # This gives us an integer
print('number of items in the list is:', length)