Explanation:
1. Creating the Data Structure
data = [[1, 2], [3, 4]]
data is a list.
Inside it, there are two smaller lists:
First list: [1, 2]
Second list: [3, 4]
So, this is a 2D list (list of lists), similar to a table:
[
[1, 2], → index 0
[3, 4] → index 1
]
2. Understanding Indexing
Python uses zero-based indexing, meaning:
First element → index 0
Second element → index 1
So:
data[0] → [1, 2]
data[1] → [3, 4]
3. Accessing Nested Elements
data[1][0]
Break it step by step:
Step 1: data[1]
Selects the second list
Result: [3, 4]
Step 2: [3, 4][0]
Selects the first element of that list
Result: 3
4. Final Output
print(data[1][0])
Prints the value:
3

0 Comments:
Post a Comment