码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-01-16 20:53:07      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:milang   python   

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

标签:milang   python   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!