what is an instance in python code example
Example 1: what is a ython instance
An object belonging to a class. e.g. if you had an Employee class, each
individual employee would be an instance of the Employee class
Example 2: instance method in python
class Student:
def __init__(self, a, b):
self.a = a
self.b = b
def avg(self):
return (self.a + self.b) / 2
s1 = Student(10, 20)
print( s1.avg() )
Example 3: python instance Object
x.counter = 1
while x.counter < 10:
x.counter = x.counter * 2
print(x.counter)
del x.counter