python中len()方法描述
len() 方法返回<a href="https://www.gaodaima.com/tag/%e5%88%97%e8%a1%a8" title="查看更多关于列表的文章" target="_blank">列表</a>元素个数。
www#gaodaima.com来源gaodai$ma#com搞$代*码*网搞代码
语法
len()方法语法:
len(list)
参数
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 lsit length : 2
推荐学习《python教程》
来源:搞代码网:原文地址:https://www.gaodaima.com