Python3 List append() method usage

In this article, let’s learn about Python’s append method for lists.

Introduction

The list append() method adds a new element() to the end of the current list object.

Grammar

Syntax of the append() method.

list.append(x) # cnpython hint: where x is the element to be appended to the end of the list

Passing parameters

The element x is the object appended to the end of the list.

Python lists are mutable data types, so they are modified in place and no new objects are created.

Practical Cases

Let’s take a look at the demonstration of the list append function method.

L = [123, 'xyz', 'zara', 'abc']
L.append( 2009 )
print("The updated L list is : ", L)

The output in the Python terminal is as follows.

The updated L list is : [123, 'xyz', 'zara', 'abc', 2009]

Note that the int type 2009 in the above code is the element we append to the end of the list with the append method.
You can create an empty Python list first, and use this method to gradually add some various types of data to test it, and then you will get familiar with it.

Leave a Reply