how do you make a temporary object using the class function in python?

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!

import math
class Points(object):
    def __init__(self, x, y, z):

    def __sub__(self, no):
        return  Points((self.x-no.x),(self.y-no.y),(self.z-no.z))

    def dot(self, no):
        return (self.x*no.x)+(self.y*no.y)+(self.z*no.z)

    def cross(self, no):
        return Points((self.y*no.z-self.z*no.y),(self.z*no.x-self.x*no.z),(self.x*no.y-self.y*no.x))
    def absolute(self):
        return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), 0.5)

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.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top