![]() |
VOOZH | about |
In Python, lists are used to store multiple items in one variable. If we have an empty list and we want to add elements to it, we can do that in a few simple ways. The simplest way to add an item in empty list is by using the append() method. This method adds a single element to the end of the list.
[10]
Other methods that we can use to append elements to a list are:
Table of Content
Another way to add elements to an empty list is by using the + operator. We can concatenate the original list with another list containing the element we want to add.
[20]
The extend() method allows us to add multiple elements to a list. We can use it if we want to add more than one item at a time.
[30, 40, 50]
List unpacking is a more advanced method but it’s still a great option to add elements to a list.
[60]