Questions about the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Questions about the code

1)Was in this code the definition of classmethod as decorator? 2)Rectangle.new_square return (5, 5). It returns it in Rectangle or not? If not, were it is in the output? class Rectangle: def __init__(self, width, height): self.width = width self.height = height def calculate_area(self): return self.width * self.height @classmethod def new_square(cls, side_length): return cls(side_length, side_length) square = Rectangle.new_square(5) print(square.calculate_area()) Thanks in advance!

17th Aug 2018, 9:46 AM
Ilyich
1 Answer
+ 4
class a: def __init__(self): pass @classmethod def b(arg): print(arg) def c(arg): print(arg) @staticmethod def d(arg): print(arg) a.b() # class __main__.a x = a() # __main__.a object at ... x.c() a.d('hello world') # Hello World
17th Aug 2018, 10:52 AM
Mert Yazıcı
Mert Yazıcı - avatar