How to assign a value to next_node in the Node init method?


In this exercise, the __init__() method for the Node class takes a parameter named next_node which has a default value of None. How would a Node object be created that assigns next_node to a value?


The value provided for next_node needs to be a reference to another Node object. In most cases, a Node object is going to be created using the default value of None and then the value for self.next_node will be set as part of creating and manipulating the Node object as part of a linked list. However, the following example extends the exercise to show how a new Node object is created that will set next_node to point to the first object created.

my_node = Node(44)

my_node2 = Node(66, my_node)

I understand what you are saying here. I found the explanation of the default value portion unclear in the constructor.

For the above example the constructor was:

def init(self, value, next_node = None):

The part that wasn’t clear to me was does the “next_node = none” only set “next_node” to the default None if nothing is provided when it is being called like my_node in the sample above or is it set to none every time ie for both my_node and my_node2 from the sample above?