Learn Special Methods by Building a Vector Space - Step 10

Tell us what’s happening:

I hope this is not so stupid question:
why the following code return f’{self.x, self.y}’ passed the step, and this one, return (f’self.x, self.y), instead does not ??

is because the fstring fuction is under the str method??
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 (f'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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 10

Are you just referring to the use of brackets, or the missing quote? ’

If it’s just the brackets, extra unnecessary brackets usually will not pass a test. The tests are usually designed to accept specific input and even if something might be ok syntax, it might not be what the test is expecting.

The above is always the string 'self.x, self.y', while you want the actual values of self.x and self.y to be printed dynamically. Therefore you need to use the replacement fields ({}) to have those values evaluated and printed.

1 Like

I am referring the curly brackets {}, I do not why but I thought the () were more appropiate
Thank you guys…you are the best…