+ 1
What is the output?
n = 5 ar1 = ar2 = [] for i in range(n): ar1.append(0) ar2.append (0) print(len(ar1))
1 Antwort
+ 2
The unexpected result is 10 because ar1 and ar2 are two lists linked to the same object. So at every loop both lists are expanded by 2 elements.
If you want to define 2 differents lists you must write
ar1,ar2 = [],[]
instead of
ar1 = ar2 = []