目录

len(list)

描述 (Description)

方法len()返回list的元素数。

语法 (Syntax)

以下是len()方法的语法 -

len(list)

参数 (Parameters)

  • list - 这是要计算的元素数量的列表。

返回值 (Return Value)

此方法返回列表中的元素数。

例子 (Example)

以下示例显示len()方法的用法。

#!/usr/bin/python
list1, list2 = [123, 'xyz', 'zara'], [456, 'abc']
print "First list length : ", len(list1)
print "Second list length : ", len(list2)

当我们运行上面的程序时,它产生以下结果 -

First list length :  3
Second list length :  2
↑回到顶部↑
WIKI教程 @2018