This blog contain program that creates a number list. Then uses while loop to display elements in a list and at the same time stripping first element at each loop interval
Create a number list
num = [1,2,3,4,5,6]
Using while loop to display elements and stripping first element using [1:]
while num:
print(num)
num = num[1:]
Output
[1, 2, 3, 4, 5, 6] [2, 3, 4, 5, 6] [3, 4, 5, 6] [4, 5, 6] [5, 6] [6]
Complete Code
num = [1,2,3,4,5,6] while num: print(num) num = num[1:]