Python标准库:内置函数len(s),,本函数是返回对象s的


本函数是返回对象s的长度,所谓的长度是指容器类的数据项个数,比如字符串、元组、列表、字典等。

例子:

#len()s = ‘123456789‘soft = ‘软件‘print(s, ‘: ‘, len(s))print(soft, ‘: ‘, len(soft))l = [2,3,4,5]print(l, ‘: ‘, len(l))d = {2 : ‘two‘, 3 : ‘three‘ }print(d, ‘: ‘, len(d))

结果输出如下:

123456789:9

软件:2

[2,3,4,5]:4

{2:‘two‘,3:‘three‘}:2

蔡军生 QQ:9073204 深圳

Python标准库:内置函数len(s)

评论关闭