Python3 Stack implementation with List built-in So, inspired by this other code review, I wanted to see if I could implement a very basic stack without the linked-list approach taken by the OP in their implementation.

To that end, I came up with the following Stack class.  I wrote it for Python 3, but it actually works as-is in Python 2 as well:

class Stack:
    _stack = []

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

    @property
    def size(self):
        return len(self._stack)

    @property
    def count(self):
        return self.size

    def __sizeof__(self):
        return self.size

    def pop(self):
        if self.size == 0:
            return "Cannot pop from an empty stack."

        item = self._stack[self.size - 1]
        self._stack.remove(item)
        return item

    def peek(self):
        if self.size == 0:
            return "Cannot peek into an empty stack."

        return self._stack[self.size - 1]

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

    def __iter__(self):
        return iter(self._stack)


I'm probably missing some key parts of what one would want from a Stack, but any improvement is welcome.  Literally any improvement. 

Note there were a couple things I did intentionally:


I intentionally initialize the _stack attribute as an empty list both in the class itself and in __init__.  For some reason PyCharm complains if the attribute isn't already part of the class when being worked with in __init__, so this is more or less to get PyCharm to stop yelling at me.
I intentionally have __sizeof__ declared as referring to the size property function.  This lets len(StackObject) work if someone doesn't want to do stack.size.


With these in mind, feel free to tell me what you think, or point out any mistakes I've made.  (I'm not an expert in data structures, so I may have gotten some points messed up a little).
By far the biggest problem this code has is error handling. When popping or peeking from an empty stack this returns a string. this is really broken. For an example of why, suppose I add the string "Cannot peek into an empty stack." to the stack and then try to see what the top element is. I won't know if the answer I got was because the stack was empty, or because that string was in the stack. The solution to this is to raise an IndexError when the stack is empty. I also think that you shouldn't define either size or count, as the pythonic way of getting somethings length is to call len(x). You might also be interested to know that python lists have a pop function already, so you could just use that for your pop