title: Python linked list- Nonetype error in recursive remove function
body: <p>I am teaching myself Python and working through the construction of a singly linked list class. The class constructors, add, and display functions all work, but when trying to implement a recursive remove function, I find that either the list does not change at all, or it deletes itself entirely.  Adding print statements into the recursive function that are intended to print the value of the node generate Nonetype attribute errors, which suggest to me that I may have an issue with the arguments being passed in, as the object that I think is a node is apparently not.  I've reviewed the other Nonetype questions I've found on SE, but either they haven't shed the needed light or I've just misunderstood them.
  Class Definitions:</p>
  <pre><code>class Node:
      def __init__(self, value):
          self.data = value
          self.next_node = None
          
  class List:
      def __init__(self):
          self.head = None
  </code></pre>
  <p>Remove functions:</p>
  <pre><code>def remove(self, target):
       if(self.head == None):
            print(&quot;List is empty!&quot;)
            return None
       else:
            print(str(self.head.data))
            self.head = self.remove_target(self.head, target)
            return self.head
          
  def remove_target(self, head, target):
       print(&quot;Target: &quot; + str(target) + &quot;Head: &quot; + str(head.data)) #Nonetype errors occur here
       if(head == None):
            return head
       if(head.data == target):
            print(&quot;target found&quot;)
            head = head.next_node
            return head
       else:
            head.next_node = self.remove_target(head.next_node, target)
            return head
  </code></pre>
  <p>My previous programming experience is in c++, and I think part of the problem is that wrapper functions used to hide data members in c++ aren't really a thing in Python?  However, the same results occur when I call the recursive function directly from the test program.  Any light that can be shed would be most appreciated!</p>