whats the difference between class A(): def name(): and class A(): def name(self):?

Viewed 12

I'm first to python class and I always been using def. And I was wondering, if the class looks like

class A():
   def hi():
       print('hi')

you can use this class like

A.hi()

but when class looks like this,

class A():
   def hi(self):
       print('hi')

you have to use this class like

a = A()
a.hi()

I reckon this results are same for I can't understand what's the diffrence between these classes. Why do you use self or init for class if you can use class with the first one? This question might be weired that I'm absolutely newbie to python. I saw lot of class lectures on youtube or blogs.. but I still don't understand. It will be very helpful if you answer to this question.

0 Answers
Related