Here in this course, ı couldn’t understand what does “nodes_to_visit = [self]” do. I mean what did I achieve by placing self in a list? Does it refers to the current TreeNode class? I mean, for example:
root = TreeNode(“apple”)
Now inside the root class we have “nodes_to_visit = [self]” and here, does “self” refers to root class ?
Please add a link to the project you’re working on. It’s harder to work out what’s going on without the rest of the code and its context.
Generally self is used to refer to the instance objects created from your class, not the class itself. I assume this is an intermediate step (incomplete code) and the children of this node would subsequently be traversed. If you’re unsure about using self then take a step back and spend some time making sure you’ve got it because it’s vital for using classes and methods.