I was working on the Python Exercise on Inheritance and Polymorphism , Dunder II.
I wrote the below code as an experiment
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 sodium = Atom("Na") print(sodium.label) #Output : Na chlorine = Atom("Cl") print(chlorine.label) #Output : Cl #salt = Molecule([sodium, chlorine]) salt = sodium + chlorine print(salt.atoms) #Output : [<__main__.Atom object at 0x7f5e77d037b8>, <__main__.Atom object at 0x7f5e77d037f0>]
I am not understanding why print is not working with salt.atoms since it is a list which is a built-in data type and print should work on it perfectly.
Why is it returning the type and address of the objects in the list instead of the contents of the list ?