len() function returns the length of an object, which can either be a sequence or collection.
object passed to the
len() function is commonly one of the following:
- It can be a sequence such as a string or tuple.
- It can also be a collection such as a dictionary or set.
The example below demonstrates how the
len() function is used in a Python program:
print(len("Hello, World!"))# Output: 13
In the example below, the
len() function is used to return the length of a string, dictionary, and list: