How to access the last element and update the score?

Here is my code:

gradebook = [('physics',98),('calculus',97),('poetry',85),("history",88)]

how do i access 88 (history marks) and change it to 93?

Tuples are immutable, so what you could do is update the element in the list. general syntax:

the_list[index] = 'new value'
1 Like

i got an error

gradebook = [('physics',98),('calculus',97),('poetry',85),("history",88)]

gradebook[-1][1] = 93

print(gradebook)

[-1][1] gives me 88. i assigned 88 to 93. am i wrong?

like I said, tuples are immutable. So you need to replace the item in the list with a new tuple

or you would need to reconsider your data types.