Detailed Explanation of the Relationship between Classes and Objects in python

  • 2021-08-21 21:02:26
  • OfStack

On the search platform, classes and objects have been screened, The main problem is nothing more than two, one is to understand the two, and the other is to understand the use relationship between the two. For this site, the two systems are clear to everyone, and I believe it is difficult to be digested by everyone. This is not, give everyone a better way to understand. In the simplest words, quickly hand over to everyone, don't believe it, and the simple and easy-to-understand content is as follows.

2-person relationship:

Girls' lipstick is category 1, but mac, Perfect Diary, is an individual in lipstick, which is called object. This is the relationship between the two, and some people can understand it as including the situation.

Define classes/objects:


class  Class name ( Parent class ):
class Human(object):
 pass
man = Human()

Example usage:


class A(object):
 name = " Class variable "
 @classmethod
 def classfunc(cls):
   print(" Class method ")
 def __init__(self, name):
   self.name = name
 def func(self):
   print(" Instance method ")

We can see from the above content that the class interview contains methods and variables, which can be called by the class at will, so the object can use the methods and variables in the instance, which constitutes the use of classes and objects.


Related articles: