Aug-13-2020, 04:06 PM
The program above doesn't produce that output. The body of the loop isn't indented properly, and the pop function is shown without parentheses, so it would just return the function object.
If you changed it instead to
If you changed it instead to
l = [10, 20, 30, 40] while len(l) != 0: print(l.pop())Then it would match the output. The
pop()
method on a list both removes the final element and returns that element. In the loop above, this shortens the list and prints the final element. Since the list is being shortened, that provides the decrement.