Answers for "how to print alternate numbers in python"

1

how to print alternate numbers in python

list = [1,2,3,4,5]
alternate_list = list[::2] 
#as we are looking for even indices only, and 2 is the smallest even number
#so, using list[::2] slices every second item of the list 
for item in alternate_list:
  print(item)
 
#Hope this helps:)
Posted by: Guest on May-17-2021

Code answers related to "how to print alternate numbers in python"

Python Answers by Framework

Browse Popular Code Answers by Language