class Atom: def __init__(self, label): self.label = label def __add__(self, other): return Molecule([self, other]) class Molecule: def __init__(self, atoms): if type(atoms) is list: self.atoms = atoms
Above is the solution to the exercise that asks to give
.__add__(self, other) method that returns a Molecule with the two
What i don’t get is in the add method, return Molecule([self, other]), how does Python know what Molecule is? Molecule as a subclass of Atom is defined after the Atom’s class definition. So, why would this code run?