Python's len function is used to return the length of strings, lists, dictionaries, tuples, etc. The syntax is [len(str)], where str is the string, list, dictionary, tuple, etc. to be calculated. .
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
The len() function in Python
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
4: Return value: string, list, dictionary , the length of elements such as tuples
Example
1. Calculate the length of the string:
>>> s = "hello good boy doiido" >>> len(s) 21
2. Calculate the number of elements in the list:
>>> l = ['h','e','l','l','o'] >>> len(l) 5
Related free learning recommendations: python video tutorial
The above is the detailed content of What does python's len function mean?. For more information, please follow other related articles on the PHP Chinese website!