Append python – Python List append() Method

With Append Python Method you can Appends objects at the end at the existing list. Python List append() Method is inbuild function. It now returns a new list, rather it updates the original list.  Using an append method in the list you can add numbers, strings, dictionary, another list, etc objects.

Append python - Python List append() Method

Syntax

The Syntax for the append() method is :

obj −, This is the object to be appended on the list.

Append python - Python List append() Method tutorial

Example 1

Add the new number in a list and print() both statement, before and after append()

Output : [1, 2, 3, 4]
Updated List : [1, 2, 3, 4, 5]

Example 2

This example Adding a new element to the colors list: Where the list is containing a string data type.

Output : [‘red’, ‘black’, ‘white’, ‘pink’]

Example Python List append() – Add a list to a list :

Here is an example of how to use append() method in python List.

Output : [‘apple’, ‘banana’, ‘cherry’, [‘red’, ‘yellow’, ‘red’]]

Do comment if any doubt and suggestion regarding this tutorial.

Note : This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Python 3.7

All Examples are in Python 3, so it may change its different from python 2 or upgraded version


Leave a Reply

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