Stacks

A stack is like a stack of plates. It's "last in, first out" (LIFO), which means the item that was put in the stack most recently is the first item that comes out.

Loading...

Stacks have two main methods:

  1. push : adds an item
  2. pop : removes and returns the top item

They can also include some utility methods:

  1. peek : returns the item on the top of the stack, without removing it.
  2. is_empty : returns True if the stack is empty, False otherwise

See also:

Psst. Pass it on.

. . .