0

What is a class method?

30th Aug 2016, 9:49 AM
Djaber Meghar
Djaber Meghar - avatar
4 Answers
+ 2
It is a function that is defined inside a class.
30th Aug 2016, 1:46 PM
James Flanders
+ 1
A class method belongs to the class itself unlike a normal method which belongs to an instance of the class. You don't have to instantiate an instance of the class via a constructor and then call a method when using a class method. Instead you just call <Class>.method They can be used for utilities or factory class methods as oppsed to normal methods that typically perform action on the properties of sn instance of a class.
2nd Sep 2016, 6:39 AM
Rob McBryde
Rob McBryde - avatar
0
tnx
2nd Sep 2016, 9:08 AM
Djaber Meghar
Djaber Meghar - avatar
- 2
it is a function into the class with self as argument. you can call the function when you create an object with the class class Dog: def __init__(self,name): self.name = name def bark(self): print(self.name,"says Woof") >>> fido = Dog("Fido") >>> fido.bark() "Fido says Woof"
8th Sep 2016, 6:22 PM
Giovanni Gatto
Giovanni Gatto - avatar