首页 > IT职业 > IT职场 > python怎么知道列表大小

python中len()方法描述
len() 方法返回列表元素个数。
语法
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教程》
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/166/viewspace-2835255/ ,如需转载,请注明出处,否则将追究法律责任。