How to Use List len() Method in PythonPython Basics


The len() method gets the total number of elements in the list.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

list1 = ['MIT', 'CIT', 'Yale','UCI']
list1.append('NYU')
print ("The new list is: ", list1)
print (len(list1))

Output:

The new list is:  ['MIT', 'CIT', 'Yale', 'UCI', 'NYU']
5

Syntax

len(list)

Parameters

Name Description
list A list whose elements to be calculated.

Return Value

It returns the number of items in the list.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us