Sep-18-2018, 05:59 PM
List are reference variables. They are always pass as reference.
When you assign one list to all variables.
It all point to the same list.
Examples
When you assign one list to all variables.
It all point to the same list.
Examples
import numpy as np td =[np.Inf, 2, 3] a = {} for k in range(10): a[k] = td # point to one list a[0][0] = 1 td[1] = 10 for i in a.items(): print(i) b = {} for k in range(10): b[k] = td[:] # shallow copy b[0][0] = 2 td[1] = 0 print() for i in b.items(): print(i)
a = [1, 2, 3] b = a c = a[:] # shallow copy print(a) print(b) print(c) print() a[1] = 6 b[0] = 5 c[2] = 7 print(a) print(b) print(c)
99 percent of computer problems exists between chair and keyboard.