len()
Published May 23, 2022Updated Sep 14, 2023
Contribute to Docs
The built-in len()
function returns the length of an object, which can either be a sequence or collection.
Syntax
len(object)
An 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.
Example
The example below demonstrates how the len()
function is used in a Python program:
print(len("Hello, World!"))# Output: 13
Codebyte Example
In the example below, the len()
function is used to return the length of a string, dictionary, and list:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.