0

Regarding Python methods

what is the difference it makes when declaring a method in generic way and declaring the method below "@classmethod" keyword? Is @classmethod " really a keyword of python or universally accepted programatic way?

1st May 2020, 7:10 PM
Senthil Kumar
Senthil Kumar - avatar
2 Antworten
+ 2
@classmethod is a shortcut for this older way of writing: f = classmethod(some_function) The difference is just that instead of an instance, the class is passed when you call it.
1st May 2020, 9:07 PM
HonFu
HonFu - avatar
+ 1
The way itself is typical for many languages. In C# e.g. it is called static. They are used for things which do not have to be represented in objects. Think about using methods of Math. It are calculations, which do not have a state outside the method. In difference to that a calculator presented to a user may have a state, the result of a calculation with which you might want to proceed calculating. Of course you could hold that value once only, but latest when you can show two calculators at the same time you need to organize them, for which objects are designed.
1st May 2020, 7:22 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar