List append with 2 arguments

Hello!

When reading the documentation I came across the information that .append takes only 1 argument. (I previously tried to pass in 2 arguments and noticed it returns a very explicit error). In this part of the exercise, I see it shows .append with 2 arguments and double parenthesis.

Is this considered best practice? Why is this working? Also, I read as a suggestion on other website that it would be preferred to use extend. Could that be a better alternative or it is used in other cases?

Thank you a lot!

.append() method has 1 parameter as signature, so it can only take a single argument

what you do here is appending a tuple (an immutable list) to a list.

tuple just like list are just 1 container, the container can contain multiple values but its still 1 container/1 argument

you can also do:

some_list.append([1, 2, ,3])

this will give nested lists.

its important to be aware of how this works, and what the difference between append and extend is. You might run into cases where you get to work with nested lists.

1 Like

Wow, that was super explicit and really fast. Thank you a lot, everything is super clear now! :pray: :pray::pray:

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.