Concept

len()

len() function returns the length or number of items in an object. The object must be a sequence e.g string, list, tuples or a collection e.g dictionary, set.

print(len("apple")) #returns 5 print(len(["a", "b", "c"])) #returns 3 print(len({"age": 20, "score": 100})) #returns 2 print(len(1)) #throws an error: TypeError: object of type 'int' has no len()

0

1

Updated 2025-09-15

Tags

Python Programming Language

Data Science

Related