Implement a stack class in Python Problem : Implement a stack class in Python. It should support 3 APIs:
  
  stack.top(): prints element at top of stack
  
  stack.pop(): takes out an element from top of stack, 
  
  stack.push(): adds a new element at top of stack


Does this code covers all the edge cases of implementing a stack?

class Stack():

    def __init__(self):
        self.item = []

    def size(self):
        return len(self.item)

    def top(self):
        if len(self.item) &gt;= 1:
            print self.item[len(self.item) -1]
        else :
            print "Empty list"

    def pop(self):
        if len(self.item) &gt;= 1:
            self.item.pop()
        else:
            raise IndexError 

    def push(self,item):
        self.item.append(item)
        print self.item


new_stack = Stack()
new_stack.push(19)
new_stack.push(20)
new_stack.push(119)
new_stack.push(202)
new_stack.push(195)
new_stack.push(205)
new_stack.push(149)
new_stack.push(230)

print new_stack.size()
new_stack.top()
new_stack.pop()
new_stack.top()
new_stack.pop()
new_stack.pop()
new_stack.pop()
new_stack.pop()
new_stack.pop()
new_stack.pop()
new_stack.pop()
new_stack.top()
Thanks for sharing your code,

instead of using size, you should implement __len__, this way you can use len(my_stack).

def __len__(self):
    return len(self.item)


I think a method that prints an element from a collection is a bit unusual. What I would expect is a method called peek that returns the top element but doesn't remove it. By just printing it you're limiting its use to console only applications, and the only way to retrieve the element is to remove it!

You should consider adding an error message to go with your IndexError, and maybe reconsider the exception type, an IndexError sounds like you're accessing an index, but you're not maybe a custom StackEmpty exception would be more suitable.

I think self.item should be self.items (plural) as it will be representing zero or more items.

Bonus Stuff

you could implement the __iter__ method. This would allow the caller to do something like

for element in my_stack:
    do_stuff()


You code is also missing docstrings, you could optionally add those to document your code.

You could implement the __str__ method to provide a nice string representation so you can simply say

print my_stack

Hopefully you found this helpful, keep it up!