Introduction
The len() function helps you find out how many items are in something, like a list or a word.
Jump into concepts and practice - no test required
The len() function helps you find out how many items are in something, like a list or a word.
len(some_object)some_object can be a string, list, tuple, dictionary, or other collections.
The function returns an integer number representing the count of items.
len("hello")
len([1, 2, 3, 4])
len({"a": 1, "b": 2})
This program counts the letters in the word "apple" and the number of fruits in the list.
word = "apple" fruits = ["apple", "banana", "cherry"] print(len(word)) print(len(fruits))
If you use len() on an empty string or list, it returns 0.
Trying len() on a number will cause an error because numbers don't have length.
len() tells you how many items are inside something.
Works with strings, lists, dictionaries, and more.
Returns a number you can use to make decisions or loops.
len() function do in Python?len()len() function counts how many items are inside an object like a string, list, or dictionary.len() counts items [OK]len() to find the length of a list named fruits?len(fruits).my_list = [10, 20, 30, 40] print(len(my_list))
my_list contains 4 items: 10, 20, 30, and 40.len() to the listlen() function returns the number of items, which is 4.my_string = "hello" print(len my_string)
len is called without parentheses.data = {'a': 1, 'b': 2, 'c': 3}. You want to check if it has exactly 3 keys before processing. Which code correctly uses len() for this check?len() on a dictionary returns the number of keys.len(data) equals 3, which is correct. Other options check for greater than, less than, or not equal, which do not match the requirement.