Return the top element without removing it. Returns: The top element. Raises: IndexError: If the stack is empty.
(self)
| 184 | return value |
| 185 | |
| 186 | def peek(self) -> object: |
| 187 | """Return the top element without removing it. |
| 188 | |
| 189 | Returns: |
| 190 | The top element. |
| 191 | |
| 192 | Raises: |
| 193 | IndexError: If the stack is empty. |
| 194 | """ |
| 195 | if self.is_empty(): |
| 196 | raise IndexError("Stack is empty") |
| 197 | return self.head.value |