Learn Special Methods by Building a Vector Space - Step 10

Tell us what’s happening:

Hello. Can anyone help with this step? I don’t understand why it won’t print 2, 3. It will print 2, if I use return str(self.x), but once I include self.y, I get an error saying that ‘encoding’ must be a str, not int.

Thank you.

Your code so far


# User Editable Region

class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def norm(self):
        return (self.x**2 + self.y**2)**0.5
        
    def __str__(self):
        return str(self.x, self.y) 

v1 = Vector(2, 3)
print(v1.norm())
print(v1)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 10

Welcome to the forum :wave:

Does the str() function take multiple arguments like print()?

Ohhhhh. Thanks! I got it now. I appreciate the help.
I just needed to use an F-string to concatenate the two integers.

1 Like