0

Python help!

Hi, I can’t understand why the answer to this is 5? Thank you! a = [x for x in range(4)] print(sum(a[2::-2] + a[::-3]))

27th Jan 2022, 8:51 AM
K Ka
3 ответов
+ 5
First you have : a == [0,1,2,3] and a[2::-2] == [2,0] # -2 is the step in this case. and you have also : a[::-3] == [3,0] so a[2::-2]+a[::-3]==[2,0,3,0] and the sum is 5 #for more precision a[::-3] == [a[-1] , a[-4]] a[2::-2] == [a[2] , a[0]] a[::] == a
27th Jan 2022, 9:48 AM
YoPycode
+ 1
YoPycode Thank you!
27th Jan 2022, 11:17 PM
K Ka
+ 1
K Kana You are welcome! Good luck 👍
28th Jan 2022, 1:39 AM
YoPycode