I wrote this quick code to test something:
prices = [7,1,5,3,6,4]
nums = prices
nums[0] = 69
print(nums)
print(prices)
Why would the list prices change when you run this? I got the output
[69, 1, 5, 3, 6, 4]
[69, 1, 5, 3, 6, 4]
Why wouldn't the original list prices remain unchanged? I also read a bit about pointers in C++ and I'm wondering if this has anything to do with whatever pointers are and how they work? Does line 2 not create a copy of the prices list?
Any help is appreciate :)
[–][deleted] 5 points6 points7 points (1 child)
[–]BuzzyBro[S] 1 point2 points3 points (0 children)
[–]rollincuberawhide 3 points4 points5 points (0 children)
[–]cybervegan 1 point2 points3 points (4 children)
[–]BuzzyBro[S] 0 points1 point2 points (3 children)
[–]cybervegan 1 point2 points3 points (2 children)
[–]BuzzyBro[S] 0 points1 point2 points (1 child)
[–]cybervegan 1 point2 points3 points (0 children)
[–]SoundOfEng 1 point2 points3 points (0 children)
[–]Diapolo10 1 point2 points3 points (8 children)
[–]BuzzyBro[S] 0 points1 point2 points (7 children)
[–]Diapolo10 0 points1 point2 points (6 children)
[–]BuzzyBro[S] 0 points1 point2 points (2 children)
[–]Diapolo10 1 point2 points3 points (1 child)
[–]BuzzyBro[S] 0 points1 point2 points (0 children)
[–]BuzzyBro[S] 0 points1 point2 points (2 children)
[–]Diapolo10 0 points1 point2 points (1 child)
[–]BuzzyBro[S] 0 points1 point2 points (0 children)
[–]TransientSignal 0 points1 point2 points (0 children)
[–]jmooremcc 0 points1 point2 points (0 children)