Python len() Function
Example
Return the number of items in a list:
mylist = ["apple", "banana", "cherry"]
x = len(mylist)
Run example »
Definition and Usage
The len()
function returns
the number of items in an object.
When the object is a string, the len()
function returns the
number of characters in the string.
Syntax
len(object)
Parameter Values
Parameter | Description |
---|---|
object | Required. An object. Must be a sequence or a collection |