Python List append() Method

Python list append() method is used to add an element to the end of the list.

Syntax

list.append(item)

Parameters

item(required): It is the item(numbers, strings, another list, a dictionary) you want to add to the end of the list

Return value

The method doesn’t return any value (returns None).

Visual Representation

Visual Representation of list.append() method

Example 1: How to Use list append() Method

numbers = [1, 2, 3]

numbers.append(4)

numbers

Output

How to Use list append() Method

Example 2: Adding list to list

Visual representation of Adding list to list using list.append()

GoT = ['Daenerys', 'Jon', 'Tyrion']
Friends = ['Rachel', 'Monica', 'Phoebe']

GoT.append(Friends)
print(GoT)

Output

['Daenerys', 'Jon', 'Tyrion', ['Rachel', 'Monica', 'Phoebe']]

Time Complexity for Append in Python

The list append() method has constant time complexity, i.e., O(1), because lists are randomly accessed so that the last element can be reached in O(1) time. That’s why the time taken to add the new element at the end of the list is O(1).

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.