wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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])

Open in App
Solution

Here, the elements of the list will be printed which are at index such that index%2==0. The index of the list can be represented as:
Element 1 2 3 4 5 6 7 8 9 10
Index 0 1 2 3 4 5 6 7 8 9

Therefore, the output will be the elements at index 0, 2, 4, 6, 8 i.e.
1
3
5
7
9

flag
Suggest Corrections
thumbs-up
5
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon