Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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:)
 
PREVIOUS NEXT
Tagged: #print #alternate #numbers #python
ADD COMMENT
Topic
Name
4+3 =