无涯教程-Python - len(list)函数

105 阅读1分钟

Python list len()返回list中的元素数。

len(list) - 语法

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

len(list) - 返回值

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

len(list) - 示例

以下示例显示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

参考链接

www.learnfk.com/python/list…