PW Akshay

Generation

generate functionFri, 02 Dec 2022

Write a Python program to implement a stack using list.

class Stack: def __init__(self): self.stack = [] def is_empty(self): return self.stack == [] def push(self, item): self.stack.append(item) def pop(self): return self.stack.pop() def size(self): return len(self.stack) s = Stack() print(s.is_empty()) s.push(4) s.push('dog') print(s.pop()) print(s.size())

Questions about programming?Chat with your personal AI assistant