I am just working through some intros to Python. Basically I read about a concept and then have a play around to make sure I understand it. Right now, I'm on lists.
I wrote the following program to test a few commands:
Please could someone explain to me why this is the case?
Thanks
Stephen
I wrote the following program to test a few commands:
test_list = [1,2,3,4] print (test_list[0]) print (test_list[2]) print (test_list[-1]) sub_test_list = test_list[1:3] print (sub_test_list) naturals = [0,1,2,3,4,5,6,7,8,9,10,11,12] evens = naturals[2::2] print(evens) odds = naturals[1::2] print(odds) primes = odds primes[4:6]=[11,13] print(odds) # OP originally had this bolded print(primes) naturals.append(13) print(naturals)The bit that confused me is the command 'print(odds)' towards the bottom in bold. I was still expecting odds to be [1,3,5,7,9,11] as the change was applied to the list 'primes'. However, both 'odds' and 'primes' were printed as [1,3,5,7,11,13].
Please could someone explain to me why this is the case?
Thanks
Stephen