Cheap Jerseys Cheap NFL Jerseys Cheap NFL Jerseys Cheap Football jerseys Cheap NFL Jerseys Wholesale Jerseys Cheap NHL Jerseys Cheap Jerseys From China Cheap MLB Jerseys Cheap Jerseys Cheap Jerseys Cheap Jerseys Wholesale Jerseys Python List append() Method Tutorial - WTMatter

Python List append() Method Tutorial

Python List Append() Method

This is a tutorial of the Python List append() Method. Learn to add any new item at the end of a Python List using the append() method with examples.

Python List append() Method

The append() method is used to append or add a new item (which can be any Python object) at the end of an existing Python List.

Syntax

append() Parameters

The method append() only takes a single argument that is the item which is needed to be added or appended at the end of the list. As mentioned earlier, this item can be any Python Object such as an Integer, String, another List, Dictionary or anything else.

append() Return Value

Obviously, this method would not have anything to return, so it simply returns None.

Examples

This method is quite easy and quick to use. Have a look at the following examples to quickly understand the different use cases of the Python List append() method.

Example 1. Appending a new Element into List

In the above python code, we initially have a List defined for different fruit names. Then we’ve used the append method to add a new fruit into the list. Then we’re simply using the print() statement to check the updated list.

Python List Append() Method Example 1

Example 2. Appending another List into an existing List

Here, we’re just appending a List named indoor_games into another list named outdoor_games.

Python Append() Method Example 2

Note. Observe that the new list is appended into the existing list as a single item. Therefore, the items of the list indoor_games are actually the sub-items of the single-appended list. This is also an example of a Nested List created using the Python List append() method. If you just want to merge or concatenate two lists, you can use the + operator between two lists that you want to merge. I have already illustrated this in the following linked article.

I hope you found this guide useful. If so, do share it with others who are willing to learn Python and other programming languages. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

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