Not understanding some composition aspects (not composition)
<p>I am brushing up on some data structures and algorithms with Python, so I am implementing an Unordered Linked list. Within the same file I first wrote a Node class followed by a List class. What I don't get is how the "current" variable in my search_item() method seems to be a node object or at least able to access the Node class methods and attributes. I noticed that if I comment out my add_node() method then "current" no longer has access to Node's methods. Now I am not explicitly using neither inheritance nor composition, so I am having a hard time seeing how current just gets to call get_next() the way the code is written below. I would think I'd have to declare current as: current = Node(self.head) but just current = self.head seems to work?
Your help would be greatly appreciated.</p>

<pre><code>class Node:
    def __init__(self, data):
        self.data = data
        self.next = None

    def get_data(self):
        return self.data

    def set_data(self, d):
        self.data = d

    def get_next(self):
        return self .next

    def set_next(self, n):
        self.next = n

class UnorderedList:
    def __init__(self):
        self.head = None

    def add_node(self, item):
        tmp = Node(item)
        tmp.set_next(self.head)
        self.head = tmp

    def search_item(self, item):
        current = self.head
        # current = Node(self.head)
        found = False
        while current != None and not found:
            if current.get_data() == item:
                found = True
            else:
                current = current.get_next()
        return found
</code></pre>