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:

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy