[Solved] different between append list to array python [closed]


They only reason to use method two is because you want to create a copy of arr2. Changes to the copy would not affect the original.

Python 3.6.8 (default, Feb 14 2019, 22:09:48)
[GCC 7.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> arr1 = []
>>> arr2 = [1,2,3,4,5]
>>> arr1.append(list(arr2))
>>> arr1.append(arr2)
>>> arr2[0] = 9
>>> print(arr1)
[[1, 2, 3, 4, 5], [9, 2, 3, 4, 5]]

solved different between append list to array python [closed]