Python len() function
Example
Return the number of items in the list:
mylist = ["apple", "banana", "cherry"] x = len(mylist)
Definition and Usage
The len() function returns the number of items in the object.
When the object is a string, the len() function returns the number of characters in the string.
Syntax
len(object)
Parameter Value
Parameter | Description |
---|---|
object | Required. Object. Must be a sequence or collection. |
More Examples
Example
Return the number of characters in the string:
mylist = "Hello" x = len(mylist)