Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python List len() method

Python List len() method

Python Lists Python Lists


Description

The len() method returns the number of elements in a list.

Syntax

len() method syntax:



len(list)

Parameters

Return Value

Returns the number of elements in the list.

Example

The following example shows how to use the len() function:



#!/usr/bin/python



list1, list2 = [123, 'xyz', 'zara'], [456, 'abc']



print "First list length : ", len(list1);

print "Second list length : ", len(list2);

The output of the above example is:



First list length :  3

Second lsit length :  2

Python Lists Python Lists