Q:

Use a loop to display elements from a given list present at odd index positions using python programming

belongs to collection: Python Loop Exercises

0

Use a loop to display elements from a given list present at odd index positions

Given:

my_list = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

Note: list index always starts at 0

Expected output:

20 40 60 80 100

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use list slicing. Using list slicing, we can access a range of elements from a list

Solution:

my_list = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# stat from index 1 with step 2( means 1, 3, 5, an so on)
for i in my_list[1::2]:
    print(i, end=" ")

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a python program to rint the cube of all num... >>
<< Reverse a given integer number using python progra...