How else can the is_empty() method of the Stack class be implemented?


#1

Question

Is there another way to implement the is_empty() method of the Stack class be implemented?

Answer

The purpose of the is_empty() method is to determine whether the Stack has any items. One method for doing that is checking the value of self.size. If the value is 0, then the Stack is empty. Another option is to check the value of self.top_item. If the value is None, then the Stack is empty.