For some reason children
is static in this situation even though I'm declaring it as an instance variable. Currently using python 3.7.5
class Node:
def __init__(self, value, children=list()):
self.value = value
self.children = children
def add_child(self, child):
self.children.append(child)
a = Node(1)
b = Node(2)
a.add_child(b)
What will happen in this situation is that a.children
and b.children
will be the same. But, I thought that if I used self.children =
that the member would be part of the instance and not the class. I thought that children would only be static if it was declared like this:
class Node:
children = list()