Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

iterate through a list and print from index x to y using for loop python

fruits = ["apple", "orange", "banana", "orange", "mango", "strawberry", "lichi", "tangerine", "kiwi", "pineapple"]
start_from = 1
end_before = 8
increment_by = 2
for i in range(start_from, end_before, increment_by):  # This will not work for sets as sets are not ordered
    print(f"{i + 1}. {fruits[i]}")
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #iterate #list #print #index #loop #python
ADD COMMENT
Topic
Name
7+7 =