LearnFrenzy
Sign in Take a free test

Lists · Lists MCQ · Question 10

A float as a list index Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What happens with a[len(a) / 2]?

  • A It returns the middle item
  • B TypeError: list indices must be integers, and / returns a float; use // Correct
  • C It rounds the index
  • D IndexError
Correct Answer: Option B

Even when the division is exact, len(a) / 2 is a float such as 2.0.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links