python函數:len()
1:作用:返回字符串、列表、字典、元組等長度
2:語法:len(str)
3:參數:
str:要計算的字符串、列表、字典、元組等
4:返回值:字符串、列表、字典、元組等元素的長度
5:實例
5.1、計算字符串的長度:
>>>s="hellogoodboydoiido"
>>>len(s)
21
5.2、計算列表的元素個數:
>>>l=['h','e','l','l','o']
>>>len(l)
5
5.3、計算字典的總長度(即鍵值對總數):
>>>d={'num':123,'name':"doiido"}
>>>len(d)
2
5.4、計算元組元素個數:
>>>t=('G','o','o','d')
>>>len(t)
以上內容為大家介紹了python中的len是什么意思,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。