+ 2

Why am I getting index out of range at num.pop(3)?

num = ['1' '2','3','4','5','6'] num_pop1 = num.pop(0) num_pop2 = num.pop(1) num_pop3 = num.pop(2) num_pop4 = num.pop(3) num_pop5 = num.pop(4)

19th Sep 2021, 2:40 PM
Oral Napier
1 Antwort
+ 4
You could see the answer when you use print between. After that the list is shorter, and shorter … num = ['1' '2','3','4','5','6'] print(num) num_pop1 = num.pop(0) print(num) num_pop2 = num.pop(1) print(num) num_pop3 = num.pop(2) print(num) num_pop4 = num.pop(3) num_pop5 = num.pop(4) Output: ['12', '3', '4', '5', '6'] after pop[0] ['3', '4', '5', '6'] after pop[1] ['3', '5', '6'] after pop[2] ['3', '5']
19th Sep 2021, 2:45 PM
JaScript
JaScript - avatar