My teacher told me that purchase_list=my_list
is passing by reference/address. For example:
my_list = ['pen' , 'pencil' , 'cell phone' , 'axiom team' , 'panacloud' ]
purchase_list = my_list
my_list.append('x')
print(my_list)
print(purchase_list)
gives the following output
['pen', 'pencil', 'cell phone', 'axiom team', 'panacloud', 'x']
['pen', 'pencil', 'cell phone', 'axiom team', 'panacloud', 'x']
then why is that when i do the following:
my_list = ['pen' , 'pencil' , 'cell phone' , 'axiom team' , 'panacloud' ]
purchase_list = my_list
my_list=["Naufil"]
print(my_list)
print(purchase_list)
gives me output:
['Naufil']
['pen', 'pencil', 'cell phone', 'axiom team', 'panacloud']
and doesn't
['Naufil']
['Naufil']