Python List append()

The append() method in Python adds an element to the end of the list. After appending the new element, the size of the list increases by one.

In this tutorial, we will learn about the Python list append() method with the help of examples.

Syntax of List append() 

The syntax of the append() method is:

list.append(item)

append() Parameters

The append() method takes a single parameter.

  • item – an item to be added at the end of the list. The element can be of any data type such as number, decimal, string, character, list etc.

Return Value from List append()

The append() method doesn’t return any value.

Note: A list is an object. If you append another list onto a list, the element list that gets added will be a single object at the end of the list.

Example 1: Adding Element to a List

# Programming list
programming_list = ['C','C#','Python','Java','JavaScript']

# append the HTML item to the list
programming_list.append('HTML')
print('The new list is :', programming_list)

Output

The new list is : ['C', 'C#', 'Python', 'Java', 'JavaScript', 'HTML']

Example 2: Adding List into the List

Since we are appending a list into an existing list it would be added as a single element into the list as shown in below output.

# Programming list
programming_list = ['C','C#','Python','Java']

frontend_programming =['CSS','HTML','JavaScript']

# append the frontend_progamming list into the existing list
programming_list.append(frontend_programming)

# Note that entire list is appended as a single element
print('The new appended list is :', programming_list)

Output

The new appended list is : ['C', 'C#', 'Python', 'Java', ['CSS', 'HTML', 'JavaScript']]
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like
Check If List Is Empty Python

Check if list is empty in Python

Table of Contents Hide  How to Check if List is Empty in PythonSolution 1: Using PEP 8 recommended Style.Solution 2: Using the bool() methodSolution 3: Using the len() method.Solution 4:…
View Post