...

/

Challenge: Overload the Operators for Vectors

Challenge: Overload the Operators for Vectors

Overload the operators for Vector class.

We'll cover the following...

ed

Press + to interact
class Vector():
def __init__(self, vector):
self.vector = vector
def print(self):
print(self.vector)
# Implement this function
def __neg__(self):
return Vector([])

Overload the subtraction operator

Override __sub__() to overload the - operator.

Press + to interact
import itertools
class Vector():
def __init__(self, vector):
self.vector = vector
def print(self):
print(self.vector)
# Implement this function
def __sub__(self, other):
return Vector([])

We hope that you were able to solve the challenge.


Ask