Python List append() MethodPython 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. Syntax:Parametersx: It can be a number, list, string, dictionary etc. ReturnIt does not return any value rather modifies the list. Let's see some examples of append() method to understand it's functionality. Example 1First, let's see a simple example which appends elements to the list. Output: List before appending the element: 1 2 3 List after appending the element: ['1', '2', '3', 4] Example 2Appending a list to the list is also possible which will create a list inside the list. See the example below to understand list append. Output: List before appending the element: 1 2 3 List after appending the element: ['1', '2', '3', ['4', '5', '6', '7']] Example 3Appending multiple lists to the single list will create a nested list. Here, two lists are appended to the same list and generates a list of the multiple lists. See the example below to understand about the nested list. Output: 1 List before appending the element: 1 2 3 List after appending the element: ['1', '2', '3', ['4', '5', '6', '7', ['8', '9', '10']]] Next TopicPython list clear method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India