Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

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

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"

6 0

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online