I'm quite new to python and algorithm and I want to declare a function inside the class rather than outside of it. The followings are what I have now:

**A general Tree Class `NAryTree` implementation:**

```
class NAryTree:
    def __init__(self, key):
        self.key = key
        self.children = []
    def __str__(self):
        return str(self.key)
    def addChild(self, tree):
        self.children.append(tree)
    def getChild(self, k):
        return self.children[k]
    def getNChildren(self):
        return len(self.children)
    def __iter__(self):
        return self.children.__iter__()
    def __next__(self):
        return self.children.__next__()

```

**A function `minSubtree(tree)` to calculate the minimum sum of the subtree:**

```
def minSubtree(tree):
    value = tree.key
    for child in tree:
        value += min(minSubtree(child), 0)
    return value

```

**And a Build Tree function `buildMyNAryTree()`:**

```
def buildMyNAryTree():
    root = NAryTree(1)

    root.addChild(NAryTree(-2))
    root.addChild(NAryTree(3))
    root.addChild(NAryTree(4))

    root.getChild(0).addChild(NAryTree(-5))
    root.getChild(1).addChild(NAryTree(6))
    root.getChild(1).addChild(NAryTree(7))
    root.getChild(2).addChild(NAryTree(-8))

    root.getChild(0).getChild(0).addChild(NAryTree(-9))
    root.getChild(0).getChild(0).addChild(NAryTree(-10))
    root.getChild(0).getChild(0).addChild(NAryTree(11))
    root.getChild(1).getChild(0).addChild(NAryTree(-4))
    root.getChild(1).getChild(1).addChild(NAryTree(12))
    root.getChild(1).getChild(1).addChild(NAryTree(-13))
    root.getChild(2).getChild(0).addChild(NAryTree(14))
    return root

```

What I want is to declare `minSubtree(tree)` inside the Class, however I don't know how to change the parameter. In other word, I want to return the minimum sum of the subtree using `buildMyNAyTree().minSubtree()` instead of `minSubtree(buildMyNAryTree())`.