Python字典len()函數

Python字典len()函數計算出字典的總長度。它等於字典中的專案數。

語法

以下是len()方法的語法 -

len(dict)

參數

  • dict - 這是字典,其長度需要計算的字典。

返回值

  • 此方法返回字典的長度。

示例

以下示例顯示len()方法的用法 -

#!/usr/bin/python3

dict = {'Name': 'Maxsu', 'Age': 7, 'Class': 'First'}
print ("Length : %d" % len (dict))

當運行上面的程式,它產生以下結果 -

Length : 3

上一篇: Python字典 下一篇: Python日期和時間