返回字符串、列表、字典、元组等长度语法:len(str)
str:要计算的字符串、列表、字典、元组等
字符串、列表、字典、元组等元素的长度
1、计算字符串的长度:
>>> s = "hello word"
>>> len(s)
102、计算列表的元素个数:
>>> str= [‘h‘,‘e‘,‘l‘,‘l‘,‘o‘]
>>> len(str)
53、计算字典的总长度(即键值对总数):
>>> dict = {‘num‘:777,‘name‘:"anne"}
>>> len(dict)
24、计算元组元素个数:
>>> t = (‘G‘,‘o‘,‘o‘,‘d‘)
>>> len(t)
4原文:https://www.cnblogs.com/hanjiali/p/11589507.html