+ 3

python static class members

Hi guys, why does a static class member take additional arguements not?

29th Nov 2019, 12:53 AM
Masingita Abel
Masingita Abel - avatar
2 ответов
+ 2
In static method the class is treated as the object, thus cls parameter is required.
29th Nov 2019, 12:58 AM
Seb TheS
Seb TheS - avatar
+ 2
If you want to manipulate an instance, you take a regular method. Then the first arg will be the instance (so you can manipulate it). If you want to manipulate the class itself, you use classmethod. Again there's a forced first argument, only that this time it's the class (so you can manipulate it), not the instance. Or you want to access neither the class nor the instance. Then you use staticmethod. This time, there's no predefined argument at all, it's just like a regular function, only that it's in a class. You choose depending on what you want to do.
29th Nov 2019, 1:27 AM
HonFu
HonFu - avatar