I'm trying to set a variable and be able to change and store that variable using set and gets. The current output is:
0
0
I'm trying to get it to be:
0
2
Can some one help me understand how to change a value and then use it later in python? Kind of like a toggle?
class Spammer:
def __init__(self, spam = 0):
self._spam = spam
# getter method
def get_spam(self):
return self._spam
# setter method
def set_spam(self, x):
if x == 1:
return self._spam+1
if x== 0:
return self._spam
spammer=Spammer()
print (spammer.get_spam())
spammer.set_spam(1)
print(spammer.get_spam())