I have the following code:
class Hello(object):
def __init__(self, names):
self.names = names
def getnames(self):
return self.names
if __name__ == "__main__":
names = ['first', 'middle', 'last']
ob = Hello(names)
a = ob.getnames()
print a
a.remove('first')
print a
print ob.getnames()
The following is the output:
['first', 'middle', 'last']
['middle', 'last']
['middle', 'last']
Is it because the method getnames is mutable? Or may be there is something else going on here. Can anyone explain? How do I make the method return the original list?