Python len() Function
Example
Return the number of items in a list:
mylist = ["apple", "banana", "cherry"]
x = len(mylist)
Try it Yourself »
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 |
More Examples
Example
Return the number of characters in a string:
mylist = "Hello"
x = len(mylist)
Try it Yourself »