I'm coming from the JAVA world and reading bruce eckels' python 3 patterns idioms.
While reading about classes...it goes on to say that in python there is no need to declare class variables. You just use them in the constructor...and boom..they are there.
So for example:
class Simple:
def __init__(self1, str):
print("inside the simple constructor")
self1.s = str
def show(self1):
print(self1.s)
def showMsg (self, msg):
print (msg + ':', self.show())
My question is, if above is the case then any object of class Simple can just change the value of variable 's' outside of the class. For example:
if __name__ == "__main__":
x = Simple("constructor argument")
x.s = "test15" #this changes the value
x.show()
x.showMsg("A message")
In java, we have been taught about public/private/protected variables. Those keywords make sense because at times you want variables in a class to which no one outside the class has access to.
Why is that not required in python?