In [5]:
class Stack:

    # Python list implementation of stacks

    def __init__(self):
    # construct an empty stack
        self._stack = []

    def __str__(self):
    # string representation of stack
        return str(self._stack)
    
    def __len__(self):
    # returns number of items in stack
        return len(self._stack)

    def is_empty(self):
    # returns True if stack is empty and False otherwise
        return len(self._stack) == 0
    
    def top(self):
    # returns top item of stack if stack is not empty; otherwise returns None
        if len(self._stack) == 0:
            return None
        else:
            #return self._stack[len(self._stack)-1]
            return self._stack[-1]

    def pop(self):
    # similar to top, except this also deletes top item from stack.
        if len(self._stack) == 0:
            return None
        else:
            x = self._stack[-1]
            self._stack = self._stack[0:-1]
            # self._stack.remove(????)
            return x
    
    def push(self,e):
    # puts new item e on top of stack
        self._stack.append(e)
        
In [6]:
s1 = Stack()
s1.push(10)
s1.push(20)
s1.push(30)
print(s1)
[10, 20, 30]
In [7]:
s1 = Stack()
s1.push(10)
s1.push(20)
x = s1.pop()
s1.push(30)
print(s1)
print(x)
[10, 30]
20
In [9]:
s1 = Stack()
x = s1.pop()
print(x)
None
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
str([1,2,3])
In [ ]:
class Pancake:
    
    def __init__(self):
        self._size = 9
        self._calories = 400
        self.toppings = ['lost of cream', 'strawberry',..]
        
In [3]:
x = [1,2,3,4,5]
x[0:-1]
Out[3]:
[1, 2, 3, 4]
In [ ]:
x = [1,2,3,4,5]
x.remove(????)
In [ ]:
x = 20
print(x)
x = "Raj"
print(x)
x = True
print(x)
x = Stack()
print(x)