I have wrote following code in python
class check(object):
def __init__(self):
self.a = [1,2,3,4]
self.b = 5
appending(self.a, self.b)
print "a", self.a
print "b", self.b
def appending(a,b):
a.append(5)
b +=1
If now I run check()
function, I got output as following:
a [1,2,3,4,5] [1,2,3,4,5]
b 5 5
So, I have following question
Why it is that list(a) is got updated but not int(b)?
It is related that I am modifying a but i am creating new object when I add 1 in b, in short, it is difference due to immutable or mutable data types.
I have define self.a and self.b in object, i have define a,b in function, then why I can write print a and print b in object, get same output as self.a and self.b