Python中的len()函数
1:作用:返回字符串、<a href="https://www.gaodaima.com/tag/%e5%88%97%e8%a1%a8" title="查看更多关于列表的文章" target="_blank">列表</a>、字典、<a href="https://www.gaodaima.com/tag/%e5%85%83%e7%bb%84" title="查看更多关于元组的文章" target="_blank">元组</a>等长度 2:语法:len(str) 3:参数:str:要计算的字符串、列表、字典、元组等 4:返回值:字符串、列表、字典、元组等元素的长度
www#gaodaima.com来源gaodai#ma#com搞*代#码网搞代码
5:实例
5.1、计算字符串的长度:
>>> s = "hello good boy doiido" >>> len(s) 21
5.2、计算列表的元素个数:
>>> l = ['h','e','l','l','o'] >>> len(l) 5
更多学习内容,请点击搞代码网。
来源:搞代码网:原文地址:https://www.gaodaima.com