PRO
Ernest
asked

Expert
Abhay Jajodia answered
Hello Ernest, really nice question.
In Python, len() is a built-in function that tells you how many items are in something.
You give it an object like a list, string, tuple, etc., and it returns an integer:
languages = ['Python', 'JavaScript', 'C++']
print(len(languages)) # 3
Here, len(languages) is 3 because there are three items in the list.
It works the same way with strings:
word = "Hello"
print(len(word)) # 5
And with an empty list:
items = []
print(len(items)) # 0
So the simple way to remember it:
len(x)gives you “how many things are inside x”.
If you have further questions, I'm here to help.
Python
This question was asked as part of the Getting started with Python course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer