Skip to content
Advertisement

how to make a temporary object from withing the class function in python?

I’m writing this code and there is a need to send objects as parameters in functions. My problem is one of the objects needs to be resued with its original values but as I need to return an object from the functions.

I don’t know how I can send the answer and keep the original values in the object safe for reuse. Is there any way to make an object from the class declaration itself?

JavaScript

I want to do something like:

JavaScript

This way both input objects will have their original values but I don’t know how to get that temp.

Advertisement

Answer

Thanks everyone who helped. I got the answer to what I was looking. I wanted an object to act as a container that can store the class variables, and I didn’t knew I can just make a new object of the class from within it!

JavaScript

As you can see using points, i.e the constructor for class Points, I can store the result of any operations and can return it as an object while not altering my input objects.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement