+ 2
What is an instance? What is it to do with class, method or function?
4 Réponses
+ 3
An instance is an actual creation of something. A class is just a set of rules. An object is an actual instance of the class.
For example, "human" is a class of things. But I, Taylor, am an instance of a human.
+ 1
class Worker:
def __init__(self,name):
self.name = name
worker1 = Worker("Eric Taylor")
worker2 = Worker("Jim Ross")
# worker1 and worker2 are 2 istances of the class Worker
# and they are two objects made with the bleprint of class Worker
0
an object is an instance of its class
0
An instance is an previously unknown object or product of it's class !