0
Why this code output 6 m=[ [1, 2, 3], [4, 5 , 6] ] print(m[1][2])
Why this code output 6 m=[ [1, 2, 3], [4, 5 , 6] ] print(m[1][2])
13 odpowiedzi
+ 11
ZIZO Abd alkawy
That's 2D array so
m[1][2] => 1 row index and 2 col index
vertical lines -> columns
horizontal lines -> rows
m[0][0] = 1
m[0][1] = 2
m[0][2] = 3
m[1][0] = 4
m[1][1] = 5
m[1][2] = 6
+ 5
ZIZO Abd alkawy
Column
0 1 2
Row 0 [1, 2, 3]
1 [4, 5, 6]
The first index in m[1][2] refers to the row and the 2nd index refers to the column
+ 2
A͢J I didn't get it
+ 2
The element index in a parent array or othewise equates to :
[1,[1,2]] which is the third element in the second array, namely 6
+ 2
This is simple.
Start the count from 0, not 1.
+ 1
ZIZO Abd alkawy
2D array is a matrix of row and column so m has 2 rows and 3 columns
1st rows has values 1, 2, 3
2nd rows has values 4, 5, 6
So 1 is at index 0 and 0
2 is at index 0 and 1
3 is at index 0 and 2
+ 1
ZIZO Abd alkawy
This is a plain array or you can say list in python which contains normal value as well as a list. Here things will be treat as a 1 D list
"string"[2][0] = r
"string"[2][1] #error because there is no index 1
+ 1
You are using nested lists so when saying m[1][2] you are saying in m, the second list (cause the first one is 0), the 3rd object
Here is more clear explanation:
m = [
[1,2,3]
[4,5,6]
]
m[1] is [4,5,6]
m[2][3] is the 3rd index in m[1]
Which is 6
So m[1] returns the 2nd list in the og list
And ( m[1] )[3] is the 3rd object in said list
So 6
0
(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞༼ つ ◕◡◕ ༽つ(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞
0
*Index starts at 0
You access m[1], Which is the second item in the list (because to access the first one you have to do m[0])
You now have a list, You now access the 2nd index (or third item)of said list which is 6. Take a look at lists in the Python Lessons :)
- 1
AYO