len() 函数将返回传递给它的列表中值的个数,就像它能计算字符串中字符的个数一样。在交互式环境中输入以下代码:
len()
>>> spam = ['cat', 'dog', 'moose'] >>> len(spam) 3