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])

13th Feb 2022, 1:35 PM
ZIZO Abd alkawy
13 Respuestas
+ 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
13th Feb 2022, 1:40 PM
A͢J
A͢J - avatar
+ 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
13th Feb 2022, 3:26 PM
Jaz
Jaz - avatar
+ 2
A͢J I didn't get it
13th Feb 2022, 2:31 PM
ZIZO Abd alkawy
+ 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
15th Feb 2022, 6:45 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
This is simple. Start the count from 0, not 1.
15th Feb 2022, 12:30 PM
Farohiddin Kamoldinov
Farohiddin Kamoldinov - avatar
+ 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
13th Feb 2022, 3:18 PM
A͢J
A͢J - avatar
+ 1
A͢J Jaz get it thanks 😊
13th Feb 2022, 4:01 PM
ZIZO Abd alkawy
+ 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
13th Feb 2022, 4:40 PM
A͢J
A͢J - avatar
+ 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
13th Feb 2022, 5:33 PM
Muhammad Abouraya
Muhammad Abouraya - avatar
0
Is this code also like the last one number=3 things=["string", 0, [1 , 2, number],4.56] print(things[1]) print(things[2]) print(things[2][2]) this line output 3 Why there in no rows When I make the first 2 0 it outputs r Why it should output t Jaz A͢J
13th Feb 2022, 4:20 PM
ZIZO Abd alkawy
0
(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞༼ つ ◕◡◕ ༽つ(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞(☞ ͡° ͜ʖ ͡°)☞
15th Feb 2022, 1:34 PM
MariaVictorLenny Singh
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 :)
17th Feb 2022, 1:06 AM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
- 1
AYO
4th Jun 2022, 5:08 PM
MariaVictorLenny Singh