Python method that returns instance of class or subclass while keeping subclass attributes
Python method that returns instance of class or subclass while keeping subclass attributes Question: I’m writing a Python class A with a method square() that returns a new instance of that class with its first attribute squared. For example: class A: def __init__(self, x): self.x = x def square(self): return self.__class__(self.x**2) I would like to …