0

What is a static method and a class method in python ?

8th Jan 2019, 6:31 AM
Gaurav Thakur
Gaurav Thakur - avatar
3 Answers
+ 1
There is a pretty good explanation here: https://realpython.com/instance-class-and-static-methods-demystified/ I think the key concept is, usually you would create an instance of a class, then you access the attributes of that specific instance via 'instance methods'. With class methods you cannot change the attributes of an instance, only of the whole (abstract) class. And with static methods you cannot do either. Also you can check this code and compare how I used a static and a class method (sometimes it makes not much difference to the result). https://code.sololearn.com/c9z6qSA58rqQ/?ref=app
11th Jan 2019, 12:13 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Just complete the Python tutorial and you will get there :) https://www.sololearn.com/learn/Python/2473/
8th Jan 2019, 2:29 PM
Tibor Santa
Tibor Santa - avatar
0
So when should i use static method and when to go for class method
11th Jan 2019, 11:21 AM
Gaurav Thakur
Gaurav Thakur - avatar