Stacks Flashcards
1
Q
What is a stack?
A
A data structure that follows LIFO (Last In, First Out).
2
Q
How do you implement a stack using a list in Python?
A
stack = []
3
Q
How do you push an element onto a stack?
A
stack.append(item)
4
Q
How do you pop an element from a stack?
A
stack.pop()
5
Q
What happens if you pop from an empty stack?
A
It raises an IndexError unless handled properly.