Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Add Single Element to List – append() Function with Examples

append() function is used to Add an item to the end of the list.

Syntax of append() Function

The syntax of append() function in Python is:

 

Parameters of append() Function in Python

x – Where x is any item (number, strings, another list, dictionary) which is used to appended in the list. This parameter is required.

 

Compatibility

append() function is available and compatible with both Python 2.x and 3.x. This function is one of python list methods.

 

Return Value of append() Function in Python

append() function does not return anything.

 

Python append() Function Example 1

Adding an item to a list.

Output:
['apple', 'mango', 'cherry', 'orange', 'banana']

 

Python append() Function Example 2

Adding a list to another list.

Output:
['apple', 'mango', 'cherry', 'orange', ['banana', 'lime']]

Loading...
LearnAndLearn.com © 2018 - All rights reserved