python len() 函數用於返回對象的長度(項目數)。
簽名
len(object)
參數
object:必須是序列(字符串、元組、列表等)或集合(字典、集合等)的對象
返回
它返回對象的長度(項目數)。
Python len() 函數示例 1
下麵的例子顯示了字符串的長度。
strA = 'Python'
print(len(strA))
輸出:
6
說明: 上麵的例子使用 len() 函數返回字符串 strA 的長度。
Python len() 函數示例2
下麵的例子顯示了列表的長度。
listA = ['Python', 'C', 'C++', 'Java']
print(len(listA))
輸出:
4
Python len() 函數示例3
下麵的例子顯示了字典的長度。
dictA = {
'name':'Phill', 'university':'GTU', 'ID':1107
}
print(len(dictA))
輸出:
3
相關用法
- Python len()用法及代碼示例
- Python numpy string less_equal()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python list remove()用法及代碼示例
- Python locals()用法及代碼示例
- Python PIL logical_and() and logical_or()用法及代碼示例
- Python list index()用法及代碼示例
- Python ldexp()用法及代碼示例
- Python PIL logical_xor() and invert()用法及代碼示例
- Python list copy()用法及代碼示例
- Python log10()用法及代碼示例
- Python Functools lru_cache()用法及代碼示例
- Python linecache.getline()用法及代碼示例
- Python list()用法及代碼示例
- Python list insert()用法及代碼示例
- Python lzma.LZMACompressor()用法及代碼示例
- Python list pop()用法及代碼示例
- Python list sort()用法及代碼示例
- Python list reverse()用法及代碼示例
- Python string lstrip()用法及代碼示例
注:本文由純淨天空篩選整理自 Python len() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。