首页 > 编程语言 > 详细

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

时间:2015-01-16 20:52:49      阅读:264      评论:0      收藏:0      [点我收藏+]

本函数是返回对象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)

原文:http://blog.csdn.net/caimouse/article/details/42783203

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!