Instagram
youtube
Facebook
Twitter

Python Program to Calculate Length of a List

A Python Program to Calculate Length of a List?

Code Explanation:

Function Definition:
A function list_length() is defined to return the length of a list.

Using Built-in Function:
len(lst) is a built-in Python function that returns the number of elements in the list.

Input List:
A sample list [10, 20, 30, 40, 50] is used for testing.

Function Call & Output:
The function is called with the sample list and the result is printed.

 

Program:

def list_length(lst):

    return len(lst)

my_list = [10, 20, 30, 40, 50]

print("Length of the list is:", list_length(my_list))