Python3 List len() Method

Python3 列表Python3 Lists


Description

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

Syntax

The syntax of the len() method is:

len(list)

Parameters

  • list -- A list whose number of elements is to be calculated.

Return Value

Returns the number of elements in the list.

Example

The following example demonstrates the usage of the len() function:

Example

#!/usr/bin/python3

list1 = ['Google', 'Example', 'Taobao']
print (len(list1))
list2=list(range(5)) # Create a list from 0 to 4
print (len(list2))

The output of the above example is:

3
5

Python3 列表Python3 Lists

Other Extensions