I was coding with Python and a bug made me notice this.
Say, I have this code:
class test1(object):
def __init__(self):
self.hello = ["hello"]
self.text_back = test2().stuff(self.hello)
print "With list: ",self.hello[0], self.text_back[0]
class test2(object):
def stuff(self,text1):
self.asdf = text1
self.asdf[0] = "goodbye"
return self.asdf
a = test1()
#---------------
class test3(object):
def __init__(self):
self.hello = "hello"
self.text_back = test4().stuff(self.hello)
print "Without list:",self.hello, self.text_back
class test4(object):
def stuff(self,text1):
self.asdf = text1
self.asdf = "goodbye"
return self.asdf
b = test3()
The output is:
With list: goodbye goodbye
Without list: hello goodbye
I have the identical code between the two, except that one is list and one isn't. Why am I getting different results?