0

print([1,2,3,4][1:3][1]) #please explane Output

This Outputs: 3 Why?

12th Mar 2020, 6:45 PM
Andreas
6 Respuestas
+ 4
Array index start from 0, right? So, [1,2,3,4] [1:3] will get you numbers at index 1 to 3 (3 will be excluded), which will be [2,3]. Ok? And [2,3] [1] ? What'll get? Guess it! You can do it. Hope it helps! :)
12th Mar 2020, 7:02 PM
The Sylar
+ 3
[1,2,3,4][1:3]=[2,3] [2,3][1]=3
12th Mar 2020, 7:02 PM
Oma Falk
Oma Falk - avatar
+ 3
Andreas wo hing es denn jetzt?
12th Mar 2020, 7:53 PM
Oma Falk
Oma Falk - avatar
+ 2
Andreas , first the slice =>[2, 3](slices the list from index 1 to 3 excluded) and then the element at index 1 is 3.
12th Mar 2020, 7:03 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
now I get it! thank you
12th Mar 2020, 7:47 PM
Andreas
+ 1
ich habe nicht kapiert das ein index operator sich auf den vorherigen index operator beziehen kann
12th Mar 2020, 9:40 PM
Andreas