0
Can someone tell why calc is not printing?
4 Respostas
+ 1
calc() is not a class method, by default it is an instance method. That means you need to create an instance of your Rttu class, giving the argument required by the __init__ constructor. Then you can call the calc() method of that instance. Like so:
r = Rttu('my name')
r.calc()
+ 2
square = Rectangle.new_square(5)
print(square.calculate_area())
This is instantiation. You create an instance of the class Rectangle. Notice, to call the calc function you used the instance name and not the class name, so:
square.calculate_area()
and NOT: Rectangle.calculate_area()
That's why it works.
+ 1
Thanks Tibor Santa
0
But in calculating area,the same method is used to call the class functions and it's working fine,why is that?
By the way thanks for answering.