1

I want to have a original list and reversed list in python 3, so i try this code. And i found a new issue. Why aList in this code is reversed ? I thought we have 2 seperate list in here after assignment b=aList, and then i reverse b, not the aList, so why aList is reversed

aList = [123, 'xyz', 'zara', 'abc', 'xyz'];
b=aList
b.reverse()
print(aList)

The output is : ['xyz', 'abc', 'zara', 'xyz', 123] I thought the output has to be the original list because we change the b list not the aList

  • this experiment should show you that your assumption `"I thought we have 2 seperate list in here after assignment "` is wrong. [good further read](https://nedbatchelder.com/text/names.html) – Paritosh Singh Jun 22 '19 at 10:27

0 Answers0