Python List append()

In this tutorial, we will see about Python List‘s append method.Python List append is used to add single element to end of the list.

Let’s understand about basic of python list first.

Python List is nothing but the collection of elements. You can add any data type to the list.

💻 Awesome Tech Resources:
  • Looking for ⚒️ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events 🗓️ Calendar.️

You can create simple list as below

Python List append example

You can simply use append method to add elements to the end of the list.It does not return anything, just updates the list.
Let’s understand this with the help of simple example.

Output:

[‘item1’, ‘item2’, ‘item3’, ‘addedItem1’] [‘item1’, ‘item2’, ‘item3’, ‘addedItem1’, 1, 2]

You can add any python data such as list, set and tuple to the Python list using append method.

Output:

[‘item1’, ‘item2’, ‘item3’, (‘item4’, ‘item5’, ‘item6’)]

As you can see we have added tuple (‘item4’, ‘item5’, ‘item6’) as it is.You can add set too the list.

Output:

[‘item1’, ‘item2’, ‘item3’, (‘item4’, ‘item5’, ‘item6’), {1, 2, 3}]

That’s all about Python List append method.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.