Accessing 2D Lists

class_name_test = [[“Jenny”, 90], [“Alexus”, 85.5], [“Sam”, 83], [“Ellie”, 101.5]]
sams_score = class_name_test[2][1]
print(class_name_test)
print(sams_score)

question:
Use double square brackets ( [][] ) to select Sam ‘s test score from the list class_name_test .


I dont really understand why for Sams_score it is [2][1]

Hi,

Arrays are 0-indexed in python. That means you start counting from 0. Jenny → 0, Alexus → 1, Sam → 2.
"Sam"'s entry is at index 2 of the class_name_test array, and 83 is at index 1 of the array [“Sam”, 83]. Hence, class_name_test[2][1] accesses the value 83 in this example.

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.