Python List append() Method
Python append() method adds an item to the end of the list. It appends an element by modifying the list. The method does not return itself. The item can also be a list or dictionary which makes a nested list. Method is described below.
x: It can be a number, list, string, dictionary etc.
It does not return any value rather modifies the list.
Let's see some examples of append() method to understand it's functionality.
Python List append() Method Example 1
First, let's see a simple example which appends elements to the list.
1 2 3 List after appending element : ['1', '2', '3', 4]
Python List append() Method Example 2
Appending a list to the list is also possible which will create a list inside the list. See the example below.
1 2 3 List after appending element : ['1', '2', '3', ['4', '5', '6', '7']]
Python List append() Method Example 3
Appending multiple lists to the list will create a nested list. Here, two lists are appended to the list and generates a list of lists. See the example below.
1 2 3 List after appending element : ['1', '2', '3', ['4', '5', '6', '7', ['8', '9', '10']]]
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week