Hi I wonder if anyone can help:
How should I correct the line with ‘.append’?
.append() is a list method.
gradebook is a tuple.
So the first question should be: what do you need to fix and why?
@stetim94 Thank you very much for your reply.
In line 11 (in the screenshot), I was trying to complete the task ( Use the
.append() method to add a list with the values of
"computer science" and an associated grade value of
100 to our two-dimensional list of
gradebook ). When I tried to run it, I was given the error message :AttributeError: ‘tuple’ object has no attrbute ‘append’.
How should I address the error? Many thanks
Take a look at the difference between
gradebook in your code. There’s some defaulting behavior I didn’t even know about that is resulting in
gradebook not being a list.
If you’re looking for the reason it’s that separating items with
, is the standard syntax for creating a tuple. Many folks are familiar with wrapping them in parentheses which is fine. In some cases the parentheses are essential to separate the tuple creation as
, is used differently in certain contexts e.g. function calls/definitions, with literals like lists, sets etc.
It’s the reason why things like
return a, b, c are fine since you return a single object, a tuple.
hi @bavarcarus that’s spot on! Yes indeed i should add a square bracket ’ ’ to contain all the list elements. I did so and it was solved. Thank you very much!
Thanks @tgrtim . It’s great that now I know what is a tuple (through your link). Very helpful!