Home > Article > Backend Development > 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!