I am trying to understand the difference between the class attributes __value and value in below python class.
class WithClass ():
def __init__(self, val = "Bob"):
self.__value = val
def my_func(self):
print(self.value)
a = WithClass()
print(a.__value)
b = WithClass("Sally")
print(b.__value))
Above code gives error "AttributeError: WithClass instance has no attribute '__value'". But below code does not give any error.
class WithClass ():
def __init__(self, val = "Bob"):
self.value = val
def my_func(self):
print(self.value)
a = WithClass()
print(a.value)
b = WithClass("Sally")
print(b.value))
What is the difference between the declaration of two attributes? Any resources to understanding the importance of "__" in python would be appreciated.