This is probably a basic question for most of you but I can't find any specific info on by googling, nor in any of the previously asked questions:
I would like to know whether it is possible to append several items to a list already containing one item by using .append and then get the number output of all of them using len(). When I enter my code as follows:
bag.append('suit', 'shoes', 'socks')
I get the following error:
TypeError: append() takes exactly one argument (3 given)
I have tried double parentheses as follows:
bag.append(('suit', 'shoes', 'socks))
but this results in len(bag) telling me that there are only 2 items in bag (i.e. the original one & (suit, shoes, socks). The number aimed for is 4 (i.e. original item + suit + shoes + socks).
The only method I have used that has successfully accomplished this is as follows:
bag.append('suit')
bag.append('shoes')
bag.append('socks')
When running len(bag) on this, I get the correct output for the 4 items separately, i.e. 4 (original item bag = [gloves] + 'suit' + 'shoes' + 'socks'.
Rather than append, extend:
bag.extend(['suit', 'shoes', 'socks'])
See e.g. here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With