Perfect Storm1,416 Points
What's the difference between append and extend in this example?
I don't understand what differentiates append and extend. Is it that append is for one item as a string and extend is for adding multiple items?
Steven Parker163,431 Points
The "append" method adds a single item to a list, though the item might be another list. On the other hand, "extend" will add another list as individual items. You can see this in the example you provided:
list1.append(list2) list1 ['a', 'b', 'c', ['d', 'e', 'f']] # list2 is still a list, INSIDE the big list list1.extend(list3) list1 ['a', 'b', 'c', ['d', 'e', 'f'], 1, 2, 3] # but 1, 2, and 3 are separate in the big list
Happy coding! And for some holiday-season fun and coding practice, give Advent of Code a try!