In the following Python 2.7 code
a = 10
def foo(b):
b = b * 2
print a
foo(a)
variable 'a' and 'b' represents different variable spaces in memory so the result is always '10'.But in the following code
my_numbers = []
def func_while(numb):
i = 0
while i < 5:
print "At the top i is %d" % i
numb.append(i)
i = i+1
print "Number now: ", my_numbers
print "At the bottom i is %d" % i
func_while(my_numbers)
print "The numbers: "
for num in my_numbers:
print num
Appending 'numb' variable (with the help of func_while() ) automatically makes changes in 'my_numbers' variable. How come ? are 'numb' variable and 'my_numbers' are different name of the same variable block ? IF yes then why its not true in the first code. Thanks