Can someone explain me Why the output is 5? I got it in the py challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone explain me Why the output is 5? I got it in the py challenge

test = [2,4,6,9,11] x=len(test) test.append(x) print(test[5])

4th Jul 2021, 5:59 AM
Moon
Moon - avatar
3 Answers
+ 5
Mahmuda Akter Moon because it print the length of test array before it was appended at fifth index position ^^ (indexes start at 0)
4th Jul 2021, 6:04 AM
visph
visph - avatar
+ 4
x=len(test)=5 #add 5 in list test: test.append(5) list test now: test[0]=2 test[1]=4 test[2]=6 test[3]=9 test[4]=11 test[5]=5
4th Jul 2021, 6:05 AM
Cmurio
Cmurio - avatar
0
got it..
4th Jul 2021, 4:43 PM
Moon
Moon - avatar