Return the top element without removing it. Returns: The top element. Raises: IndexError: If the stack is empty.
(self)
| 109 | return value |
| 110 | |
| 111 | def peek(self) -> object: |
| 112 | """Return the top element without removing it. |
| 113 | |
| 114 | Returns: |
| 115 | The top element. |
| 116 | |
| 117 | Raises: |
| 118 | IndexError: If the stack is empty. |
| 119 | """ |
| 120 | if self.is_empty(): |
| 121 | raise IndexError("Stack is empty") |
| 122 | return self._array[self._top] |
| 123 | |
| 124 | def _expand(self) -> None: |
| 125 | """Double the size of the underlying array.""" |