how to print alternate numbers in python

Solutions on MaxInterview for how to print alternate numbers in python by the best coders in the world

showing results for - "how to print alternate numbers in python"
Lexia
20 Jan 2017
1list = [1,2,3,4,5]
2alternate_list = list[::2] 
3#as we are looking for even indices only, and 2 is the smallest even number
4#so, using list[::2] slices every second item of the list 
5for item in alternate_list:
6  print(item)
7 
8#Hope this helps:)