Class variable and instance variable

what is the difference between both access methods
self.class_variable
classname.class_variable

When you are defining class, than when we want to use non static data members of class while defining the non static member function than we use self.variable name. Non static here means, than for all different objects of class, that member would be different.

For ex: we define a class student, than data members like name, roll number, marks would be non static which means every student would have different values for them.
On the other hand if this class contains variable like total_number_of_students than this variable should be considered as static meaning no matter who the student is, its value will be same for all members.

So when we want to access static members like total_number_of_students, we use class_name.class_variable otherwise we will use self.class_variable.

Hope this cleared your doubt :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.