A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

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