0
lyst = file()

class Node:  
    def __init__(self,first,next=()):
        self.first = first
        self.next = next
    
def recursivelist(lyst):
    assert len(lyst) > 0
    if len(lyst) == 1:
        return Node(lyst[0])
    else:
        return Node(lyst[0],recursivelist(lyst[1:]))

print(recursivelist(lyst))

This will return just this: <main.Node object at 0x7f976fd24130>

When I am wanting to actually see it. Is there any way I can actually do that? I saw online that I can use the str method in the class, but I have no idea how to implement that.

Any help would be extremely helpful. Thank you so much.

Oklol2958
  • 21
  • 1
  • 8
  • Does this answer your question? [How to print instances of a class using print()?](https://stackoverflow.com/questions/1535327/how-to-print-instances-of-a-class-using-print) – Bernhard Jul 10 '20 at 05:00

1 Answers1

1

You need to implement the __repr__ and/or the __str__ function for your class, in this method you can clarify how you want an instance of your class to be represented when printed like that.

See documentation: https://docs.python.org/3.4/library/functions.html#repr https://docs.python.org/3.4/library/functions.html#func-str

Bernhard
  • 1,253
  • 8
  • 18