Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How other members of a python class are bound to the instance? [duplicate] in python ?

By M.K. Verma · 3 May 2022

How other members of a python class are bound to the instance? [duplicate] in python ?

because it's declared as a class variable, not an instance variable.

Class variable: Once copy of variable is shared between all instances.

Instance variable: Each instance has its own value and not shared between different instances of same class.

the following code will give you false.

class a:
    def __init__(self):
        self.name = 'Adam'
        self.e = [1,2,3]

b = a()
c = a()
if b.e is c.e:
    print('they are same')
else:
    print("not the same")

output

"not the same"