a = ( a [a [a [a [1] - 8 ] ] ] ). I need a little explanation on how we get 5 when executed or print. Thanks | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

a = ( a [a [a [a [1] - 8 ] ] ] ). I need a little explanation on how we get 5 when executed or print. Thanks

Help solve

17th Apr 2020, 3:38 PM
Akinpelu Kolawole
Akinpelu Kolawole - avatar
4 Answers
+ 2
Always inner operation(in brackets) gets operated first.. So, a[1] value retrieved form the array and the operation gets performed.. Similarly, after performing operations respective values gets retrieved... Hope you understand 👍
17th Apr 2020, 3:46 PM
sarada lakshmi
sarada lakshmi - avatar
+ 1
Thank you so much sarada lakshmi, I will be glad if you can expanciate more. This is the question: a = (6, 4, 4, 5, 7, 3, 10) Print(a [a [a [a [1] - 8 ] ] ]) I need explanation on how we get 5
19th Apr 2020, 8:30 PM
Akinpelu Kolawole
Akinpelu Kolawole - avatar
+ 1
Yeah!! Surely I'll explain... In the given tuple, a[1] = 4 So, a[1] - 8 = - 4 Negative indexing needs to be calculated from the last.. So, a[-4] = 5 Now, a[5] = 3 Next a[3] = 5 So,finally you'll get 5 as the result.. If you don't understand, try to take a pen and paper and start solving the same as what I said... Hope you understand 👍
20th Apr 2020, 3:35 AM
sarada lakshmi
sarada lakshmi - avatar
+ 1
This is so explanatory. Thank you so much. Am greatful.
20th Apr 2020, 6:49 AM
Akinpelu Kolawole
Akinpelu Kolawole - avatar