1 votes

Adding objects in object-oriented programming

Hello everyone, I have the following code, which has an instance method, which will have two parameters (in addition to self), which will be used to modify the properties (x, y) of the self object (the first parameter will be added to the value of the attribute "x" and the second to the property "y")

 p = suma_Poo(2.3, 6.9)
p.suma(1.0, -1.0)
print("(x = {}, y = {})".format(p.x, p.y)) # Muestra "x = 3.3, y = 5.9"


class Point:

    def __init__(self, x, y):
"""La clase cuenta con dos atributos, 'x' e 'y'"""
       self.x = x
       self.y = y

     def suma_Poo(self, v1, v2):
        sumax = v1._x + v2_x
        sumay = v1._y + v2._y
        return (sumax, sumay)

if __name__ == "__main__":

# Example
  p = suma_Poo(2.3, 6.9)
  p.suma(1.0, -1.0)
  print("(x = {}, y = {})".format(p.x, p.y)) # Muestra "x = 3.3, y = 5.9"

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X