How to insert an item into a list in Python
There are multiple ways to insert an item into a list in Python depending on your use-case. The first is append
(opens new window) which will add the item to the end of the list. There's also insert
(opens new window) to add the item at an arbitrary index. And if you need to add a list of items to a list, you can use extend
(opens new window). And in addition to extend
, you can also use +
to concatenate multiple lists together.
Python
Copy code