Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

List as a stack - LIFO

stack = []

stack.append("Joe")
print(stack)
stack.append("Jane")
print(stack)
stack.append("Bob")
print(stack)

while stack:
    name = stack.pop()
    print(name)
    print(stack)

Output:

['Joe']
['Joe', 'Jane']
['Joe', 'Jane', 'Bob']
Bob
['Joe', 'Jane']
Jane
['Joe']
Joe
[]