19th Jun 2019, 11:51 AM
Gandalf99
Gandalf99 - avatar
4 ответов
+ 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()
19th Jun 2019, 12:38 PM
Tibor Santa
Tibor Santa - avatar
+ 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.
20th Jun 2019, 3:14 AM
Tibor Santa
Tibor Santa - avatar
+ 1
20th Jun 2019, 6:34 AM
Gandalf99
Gandalf99 - avatar
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.
19th Jun 2019, 7:37 PM
Gandalf99
Gandalf99 - avatar