# You are looking for:
return "Circle with radius {radius}".format(radius=self.radius)
#but this also works :
return "Circle with {}".format(self.radius)
I don’t understand why the repr method is the only one that gets called. How come we’re not getting the area, or the circumference? They’re returning something as well… perhaps the answer is obvious but I just don’t see it.
In the learn part (left) there is an example where it’s shown that if we just try to print the object argus it will print “<main.Employee object at 0x104e88390>” and this is why we need the repr method.
class Employee():
def init(self, name):
self.name = name
def repr(self):
return self.name
argus = Employee(“Argus Filch”)
print(argus)
My question is what if we just try to print argus.name without repr method? Like this:
class Employee():
def init(self, name):
self.name = name
The parentheses aren’t necessary for a class declaration if the class you’re declaring does not inherit from another class. If we want a class to inherit the properties and methods of another class, we can declare it like so: class Employee(Person):. You’ll learn more about the concepts of inheritance and parent and child classes in this exercise.
I’d stick to declaring the class without the parentheses, like so: class Employee:.
Yeah, I’m trying to use the second one since it’s less typing, which is usually better code. But, it won’t accept it sadly, despite giving the correct output.
Why does it return a “print” without us adding the “print” function to it?
Blockquote
def repr(self):
return “Circle with radius {radius}”.format(radius=self.radius)
Like this is the solution I had success with. Why does the return statement automatically know to print the string?
I also have a sidenote question, but it has nothing to do with this, so feel free to respond or ignore: I recently learned about f-strings, and have understood its a new thing, and basically a simplified syntax for “string”.format if I understand it correctly. Any reason this is not in the lesson, and should I use it if I know about it, or is it better to stick to the “string”.format?