+ 1

Why output is different for both scenario?

Scenario 1 arr = [[]]*3 arr[0].append(7) print(arr) Scenario 2 arr1=[[],[],[]] arr1[0]=7 print(arr1)

19th Dec 2017, 4:39 PM
Ravi VK
Ravi VK - avatar
3 Answers
+ 6
sc1: arr is an arr if three identical arrays (memory address is equal) sc2 arr is an array of three different arrays
19th Dec 2017, 9:22 PM
Oma Falk
Oma Falk - avatar
+ 5
list is array
20th Dec 2017, 6:10 AM
Oma Falk
Oma Falk - avatar
+ 1
what if it is list?
20th Dec 2017, 2:22 AM
Ravi VK
Ravi VK - avatar