1. Home
  2. Data Science
  3. Python
  4. What does the len() function return in Python?

Added 25 Jan 2024

What does the len() function return in Python?

  1. Length of a string
  2. Length of a list Correct answer
  3. Length of a dictionary
  4. Length of a tuple

Correct answer

B. Length of a list

15 views

MCQSEXAM

Explanation

len() returns the number of items in an object — for example the length of a list: len([1, 2, 3]) gives 3.

The same function also works on strings, tuples, dictionaries and sets, returning the character or element count. It runs in constant time because Python containers store their size.

Practise more Computer Science MCQs with answers and explanations on MCQsExam.com.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs