This article briefly introduces the use of len () functions in Python, including the use of small examples in four cases, which is the basic knowledge in Python learning, for more information, see len ()
1: role:Returns the string, list, dictionary, and tuples.
2: syntax:Len (str)
3: parameters:
Str: string, list, dictionary, and tuples to be calculated
4: return value: Length of strings, lists, dictionaries, tuples, and other elements
5: instance
5.1. calculate the length of the string:
>>> S = "hello good boy doiido" >>> len (s) 21
5.2. number of elements in the computing 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': "doiido" }>>> len (d) 2
5.4. calculate the number of tuples:
>>> T = ('G', 'O', 'O', 'D') >>> len (t) 4