What is the difference between staticmethod and classmethod?

0 votes
I am confused between @staticmethod and @classicmethod. What is the difference between them?

I am new to Python can someone help me?
Dec 17, 2018 in Python by Anjali
• 2,930 points
56 views

1 answer to this question.

0 votes

staticmethod is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument. It is basically useless in Python -- you can just use a module function instead of a staticmethod.

classmethod, on the other hand, is a method that gets passed the class it was called on, or the class of the instance it was called on, as first argument. This is useful when you want the method to be a factory for the class: since it gets the actual class it was called on as first argument, you can always instantiate the right class, even when subclasses are involved.

For more details you can view this link:

https://www.pythoncentral.io/difference-between-staticmethod-and-classmethod-in-python/

answered Dec 17, 2018 by abc

Related Questions In Python

0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
1,915 views
+1 vote
2 answers

What is the difference between classes and labels in machine learning?

Classes and Labels both are almost same things ...READ MORE

answered Apr 3 in Python by SA
• 1,030 points
132 views
0 votes
1 answer

What is the difference between Python and IPython?

There are few differences between Python and ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 57,300 points
542 views
0 votes
1 answer

What is the difference between re.search and re.match?

The theoritical approach can be this way, re.match is ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 57,300 points
1,305 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 409 views
+4 votes
6 answers
0 votes
1 answer

sys.argv[1] what is the meaning of it?

sys.argv[1] contains the first command line argument passed to your script. For ...READ MORE

answered Dec 17, 2018 in Python by abc
274 views
0 votes
1 answer

What does calling a function means in Python?

Calling a function means that you are ...READ MORE

answered Dec 17, 2018 in Python by Shuvodip
53 views