Python List append() Method With Examples

Python list append() method adds an element to the end of the list.

Python List append() Syntax

The append() method adds a single item to the existing list. The original list length is increased by 1. It is one of the most popular list methods.

The append() method syntax is:

The append() method takes a single parameter, which is appended to the end of the list. Python list is mutable.

The element can be a number, string, object, list, etc. We can store different types of elements in a list.

List append() return value

The list append() method doesn’t return anything. You can also say that the append() method returns None.

Python List append() Example

Let’s look at a simple example to add an item to the end of the list.

Output:

Appending List to another List

If we pass a list to the append() method, it gets added as a single item to the end of the list.

Output:

Tip: If you want to append the elements of a list to another list, use the list extend() method.

Output:

Conclusion

Python List append() method allows us to add any type of data to the end of the list. The method doesn’t return anything. The original list is modified and the size is increased by 1.

References

By admin

Leave a Reply

%d bloggers like this: