Query on statement with multiple expressions 'dict[input()].append(str(a + b))'

I havent understood the code.Especially I havent understood this part of code


Breaking it down a bit is always the best way to go. As always, why not just print some of these outputs on their own?

Chances are you’ll have come across or have a reasonable idea how each of these work on their own but if not you’ll need to practice some of the earlier concepts on dictionaries, lists, user inputs, strings and integers.

input() asks for user input and returns what’s entered as a string.
d[key] returns the reference at the index key
.append() is a list method for adding a single element to a list.
str(i + 1) converts the sum of i and 1 into a string.

Edit: I changed the title for a little more relevance.

1 Like