Python3 List len()方法
描述
len() 方法返回列表元素個數。
語法
len()方法語法:
len(list)
參數
- list -- 要計算元素個數的列表。
返回值
返回列表元素個數。
實例
以下實例展示了 len()函數的使用方法:
實例
#!/usr/bin/python3
list1 = ['Google', 'zaixian', 'Taobao']
print (len(list1))
list2=list(range(5)) # 創建一個 0-4 的列表
print (len(list2))
list1 = ['Google', 'zaixian', 'Taobao']
print (len(list1))
list2=list(range(5)) # 創建一個 0-4 的列表
print (len(list2))
以上實例輸出結果如下:
3 5