I am newbie so thank you in advance
class stack():
def __init__(self):
self._stack = []
def push1(self, item):
self._stack.append(item)
import test1
a = test1.stack()
a.push1(5)
In this code it works when write in the command prompt what is above and also the code in itself in test1 module
class StackEmptyException(Exception):
pass
class my_stack:
def __init__(self):
self._stack = []
def check_input_type(inp):
if not isinstance(inp, my_stack):
raise TypeError('Expected stack; got %s' % type(inp).__name__)
def push(item, st:my_stack):
check_input_type(st)
st._stack.append(item)
def push1(self, item):
self._stack.append(item)
def pop(st:my_stack):
check_input_type(st)
to_return = None
try:
to_return = st._stack[-1]
st._stack = st._stack[:-1]
except IndexError:
raise StackEmptyException("Stack is empty") from None
return to_return
def top(st:my_stack):
check_input_type(st)
to_return = None
try:
to_return = st._stack[-1]
except IndexError:
raise StackEmptyException("Stack is empty") from None
return to_return
def is_empty(st:my_stack):
check_input_type(st)
return len(st._stack) == 0
def create_stack():
return my_stack()
However in this code when I try to to same thing it throws error
import my_stack
a = my_stack.my_stack()
a.push1(5)
AttributeError: 'my_stack' object has no attribute 'push1'
and something I didn't understand in the second part of the code why there is st:my_stack() in some functions parameters how is work what can I also may right to replace it
the code is in my_stack module