[Python] I don't understand this why it is (6, 8). Shouldn't it be (5, 9)?

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I get that v1(2) + v2(4) = 6 and v1(3) + v2(5) = 8 that would make (6, 8), but I don't understand why

    Here's the code -

    class Vector:
    def __init__(self, x, y):
    self.x = x
    self.y = y

    def __add__(self, other):
    return Vector(self.x + other.x, self.y + other.y)

    def __str__(self):
    return f"Vector({self.x}, {self.y})"

    v1 = Vector(2, 3)

    v2 = Vector(4, 5)

    print(v1 + v2)

    output: (6, 8)

    Continue reading...

Compartilhe esta Página