Home  >  Article  >  Backend Development  >  What does len mean in python

What does len mean in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-26 13:46:1640456browse

What does len mean in python

What does len mean in python? Let me give you a detailed introduction:

Function: len()

1. Function:

Return the length of string, list, dictionary, tuple, etc.

2. Syntax:

len(str)

3. Parameters:
str: ​​String, list, dictionary, tuple, etc. to be calculated

related Recommended: "Python Video Tutorial"

4. Return value:

The length of strings, lists, dictionaries, tuples and other elements

5. Example:
5.1. Calculate the length of the string:

>>> s = "hello world php cn"
>>> len(s)
18

5.2. Calculate the number of elements in the list:

>>> l = ['h','e','l','l','o']
>>> len(l)
5

5.3 , Calculate the total length of the dictionary (that is, the total number of key-value pairs):

>>> d = {'num':123,'name':"phpcn"}
>>> len(p)
2

5.4, Calculate the number of tuple elements:

>>> t = ('w','o','r','l','d')
>>> len(t)
5

The above is the detailed content of What does len mean in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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