+ 4

Can someoneone explain what is going on in the >>>print (things[2][2])? Why does it output 3?

number = 3 things = ["string", 0, [1, 2, number], 4.56] print(things[2][2])

24th Oct 2015, 11:07 PM
Kota
12 Antworten
+ 7
number = 3. number in the array at index [2] [2] is number which value is assigned as 3. The array things= ["string",0,[1,2,number], 4.56] things = ["string", 0, [1,2,3], 4.56] I hope this helps.
25th Oct 2015, 11:06 AM
Toanh Tran
Toanh Tran - avatar
+ 6
print [2][2] the first [2] refers to:(1,2,number) the second [2] refers to number
5th Dec 2015, 1:13 AM
jionn
+ 4
number is a variable which was assigned the value 3 at the beginning of the code. In list thing there's another list. The first number 2 refer to the position of the list nested in list thing. the second number 2 is the index of variable number which value is 3. Hope this will be helpful.
3rd Feb 2016, 5:11 PM
Jean Bernard FLORE
Jean Bernard FLORE - avatar
+ 2
In python when you write [ ][ ] it means you are getting into a list within a list. In your case 1st [ ] represents list of things and 2nd [ ] represents list of [1,2,number]. Another things is that count of list is starts with 0 and then 1 and then 2 and so on. So in things[2][2] means 1st [2] is position in list things which is [1,2,3] and 2nd [2] means 2nd position of this list which is 3.
6th Oct 2016, 2:11 AM
Nikhil
Nikhil - avatar
+ 1
It's point 2 of the original list (which is a nested list) and then point 2 of the nested list. I think...
28th Feb 2016, 5:28 PM
tempus
tempus - avatar
0
It means "print the second number of the second list"
2nd Apr 2016, 9:56 PM
DanielMarin
0
Remember that arrays always starts counting from 0 :)
14th Jun 2016, 1:39 AM
Vegard Bratteng
Vegard Bratteng - avatar
0
1) In things array, index[ 3 ]refers to [1,2,number] 2) In that array inner index [3] refers to number,which already assigned to 3.😀....so output =3.
12th Nov 2016, 6:17 PM
Deepak
Deepak - avatar
0
NOT FIND THIS APP HELP FUL ANY RECOMMENDATION
30th Nov 2016, 6:53 PM
DANIEL OMOTAYO UKUHOR
0
@daniwl - try YouTube "learn Python"
22nd Dec 2016, 1:39 PM
sajjad malik
sajjad malik - avatar
- 1
I think it basically means the 3rd [2] item in the list within the list (which is again the third [2] in the outer list). Hope that makes sense.
4th Apr 2016, 7:45 PM
kuku baga
kuku baga - avatar
- 1
can use plz explain that why print(things[1]) give error
25th Jun 2016, 5:05 PM
Nishant Sardana
Nishant Sardana - avatar