Apr 24, 2025
len()
function in Python is used to return the number of items in an object.len()
len(object)
object
: Required. The object can be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).mylist = ["apple", "banana", "cherry"]
x = len(mylist)
mystring = "Hello"
x = len(mystring)