I'm writing a very simple Tree class:
class Tree:
    def __init__(self, value_ = None, children_ = None):
        self.value = value_
        self.children = children_
I'd like to be able to perform both DFS and BFS traversal with a simple loop, i.e.:
t = Tree()
# ...fill tree...
for node in t:
    print(node.value)
In C++, for example, you can have multiple types of iterators - so I could define both a DFS and a BFS iterator and use one or the other depending on what type of traversal I wanted to do. Is this possible to do in Python?

Treeis not a class. It is a function. Classes are defined like:class Tree(object):definstead ofclass) - ozgur was right :)it = TreeDFSIterator(tree.begin())andit = TreeBFSIterator(tree.begin()), and that is also doable. In Python, objects have type, but since names are not objects (unlike in C++), the names themselves do not have types.