要想知道一个字符串有多少个字符(获得字符串长度),或者一个字符串占用多少个字节,可以使用 len 函数。
len 函数的基本语法格式为:
len(string)
其中 string 用于指定要进行长度统计的字符串
>>>list = [1,2,3]>>>len(list)
3
>>>l = '123'
>>>len(l)
3
>>>s = set(list)
>>>s
set([1, 2, 3])
>>>len(s)
3
长度或者元素个数的统计