Skip to content
Exercises · Q3

Q.What will be the output of the following code segment?
myList = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,len(myList)):
if i%2 == 0:
print(myList[i])

Odisha ChseTextbookSubjective· 2mImportance★★★★★est
37% · 11/30 Questions
✓ Free question

The loop prints the elements at even indexes 0, 2, 4, 6, 8. Because the list is [1..10], the element at index i is i+1, so the even positions hold the odd values: 1 3 5 7 9.

The code:

myList = [1,2,3,4,5,6,7,8,9,10]
for i in range(0, len(myList)):
    if i % 2 == 0:
        print(myList[i])

Step-by-step trace — i runs 0…9; the condition tests the index, and only even indexes pass:

ii % 2 == 0?myList[i]printed?
0yes11
1no2—
2yes33
3no4—
4yes55
5no6—
6yes77
7no8—
8yes99
9no10—

Output:

1
3
5
7
9

Why it comes out this way

  • range(0, len(myList)) generates the indexes 0 to 9, not the elements — so i is a position, and myList[i] fetches the element at that position.
  • if i % 2 == 0: filters on the index, not the value. That is the whole trick of this question: it looks like it might print even numbers, but it prints the elements sitting at even positions.
  • Here myList[i] == i + 1 (the list is just 1…10 in order), so even indexes 0,2,4,6,8 hold the odd values 1,3,5,7,9 — each printed on its own line, because every print() call ends with a newline.
✓Final answer

The output is 1 3 5 7 9, one per line — the condition i % 2 == 0 selects the elements at even indexes (0, 2, 4, 6, 8), and in this list those positions contain the odd values.

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.