Advertisements
Advertisements
प्रश्न
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])टीपा लिहा
Advertisements
उत्तर
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
shaalaa.com
Lists Methods and Built-in Functions in Python
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
