0
class StringClass:
    def __init__(self, str_value):
        self.str_value = str_value

    def __str__(self):
        return str( self.str_value)



class StringListClass:
    def __init__ (self, size):

        self.size = size  # the size of the str_list
        self.str_list = [None] * size  # the list with an initial size
        self.counter = 0  # shows which index in the list is filled

    def add (self, new_item):

        if self.size - 1 >= self.counter:
            self.str_list [ self.counter ] = new_item
            self.counter += 1
            return print ( 'Element', new_item, 'has been added, the list is :', self.str_list [:self.counter+1] )
        else:
            return print ( 'Error! Only', self.size, 'elements can be added into the list' )


list = StringListClass ( 10 )

a = StringClass ( 'Hello' )

list.add ( a )

print(a)

The result is:

Element Hello has been added, the list is : [<__main__.StringClass object at 0x1048a0cf8>, None]
Hello

I can't understand, which overloading should I use, to see not the <main.StringClass object at 0x1048a0cf8> , but the element of the list "Hello".

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172

0 Answers0