len()

CaupolicanDiaz's avatar
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:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy