+ 2

Need solution

a=[8,0,4,6,1] del(a[1::3]) print(sum(a)) How the output is 18?

17th Dec 2022, 1:55 PM
Mustakim Rahman
Mustakim Rahman - avatar
1 Answer
+ 7
The slice a[1::3] gives [0,1], because it holds references to a[1] and a[4]. Using del(a[1::3]) has the same effect as removing the reference to the values 0 and 1 in the list, so what remains is [8, 4, 6], of which the sum is 18.
17th Dec 2022, 2:48 PM
Mozzy
Mozzy - avatar