函数:len()
1:作用:返回字符串、列表、字典、元组等长度
2:语法:len(str)
3:参数:
str:要计算的字符串、列表、字典、元组等
4:返回值:字符串、列表、字典、元组等元素的长度
5:实例
5.1、计算字符串的长度:
>>> s = "hello good boy doiido"
>>> len(s)
21
Copy after login
5.2、计算列表的元素个数:
>>> l = ['h','e','l','l','o']
>>> len(l)
5
Copy after login
5.3、计算字典的总长度(即键值对总数):
>>> d = {'num':123,'name':"doiido"}
>>> len(d)
2
Copy after login
5.4、计算元组元素个数:
>>> t = ('G','o','o','d')
>>> len(t)
4
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31