Error in tree implementation with Python

Viewed 82

I am trying to implement a tree in Python but I get an error inside a method declaration.

I believe that it is due to the self instance I used:

class Node:

   def __init__(self, data=None, l=None, r=None):
       self.data = data
       self.l = l
       self.r = r

class Tree:
   def __init__(self):
       self.root = Node()

I am trying to send a node for inserting but if nothing is sent I want to reference it with the root

  def insert(self,data,root1=self.root):
      '''function definition'''

t = Tree()
t.insert(1)
2 Answers
Related