【Python】Python List len()方法

来源:互联网 发布:python struct模块 编辑:程序博客网 时间:2024/06/06 01:42

描述
len()方法返回列表元素个数。
语法

len(list)

参数

  • list要计算元素个数的列表。

返回值
返回列表元素个数。
实例
以下实例展示了len()函数的使用方法:

list1,list2 = [123,"abc"],[456,"xyz"]print ("First list length : ",len(list1))print ("Second list length : ",len(list2))

以上实例输出结果如下:

First list length :  2Second list length :  2