-2

I keep getting the error "<main.reverse object at 0x000001C1E1EAE9E8>"

class reverse:
    def __init__(self, list1):
        self.list1 = list(reversed(list1))

i = reverse([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print(i)
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
Fakhr Ali
  • 21
  • 5

1 Answers1

0

This is not "an error". This is just the default representation of objects that do not implement __str__.

You may want to implement it, ie

class reverse:
    def __init__(self, list1):
        self.list1 = list(reversed(list1))

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

See related question.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
  • So I needed to convert it to a string. – Fakhr Ali Nov 04 '18 at 16:13
  • 1
    @FakhrAli No. When you simply print an object, it is already implicitly converted to a string. But it's your responsability, as the implementer of a new class, to define (by the `__str__` method) how this conversion is going to happen. – gboffi Nov 04 '18 at 16:23