0
How does this come up with 8? How does is work?
list = [1,1,2,3,5,8,13,18] print(list(list[4])) It's print 8, but how??
4 odpowiedzi
+ 4
Hi Prasert!
Indices are always starting from zero in lists. This is the thing you have to keep in your mind when you're using lists to store data. So, list[4] is 5th element of this list that is 5. Now it becomes list([5]). Hence, list[5] is 8 which is the 6th element of this list.
+ 2
It will get the element with the index 4 and make that the index in which is 5
Then will get the element with the index 5
That becomes 8
+ 2
Your code throws an exception, as you've masked the original variable containing the reference to the actual list class. Try changing the parentheses into square brackets.
0
Python Learner could not explain it better myself