I'm addicted to handling CSV in Python, so make a note.
Suppose that the CSV of the gradebook is read by the standard library and the following list is created. Report card for 2 people. Math and English scores are recorded respectively.
paper1 = [
["Math", "90"],
["English", "75"]
]
paper2 = [
["Math", "38"],
["English", "100"]
]
At this time, which of append and + = should be used to create a list that manages a bundle of gradebooks?
Let's take a look at REPL for the time being.
>>> papers = []
>>> papers += paper1
>>> papers += paper2
>>> papers
[['Math', '90'], ['English', '75'], ['Math', '38'], ['English', '100']]
Oops? Have you been merged? This is not the expected result.
This is also a REPL.
papers = []
>>> papers.append(paper1)
>>> papers.append(paper2)
>>> papers
[[['Math', '90'], ['English', '75']], [['Math', '38'], ['English', '100']]]
Two gradebooks are included separately. This is the result I expected.
In conclusion, the + and + = operators called the extend () method. You were expanding the list of places to put it. Lists are combined.
On the other hand, the append () method appends without joining even if the object to be inserted is a list.
References https://note.nkmk.me/python-list-append-extend-insert/