How to add elements to the end of a Python List

Add to the end of Python List

The append method appends object to the end of a list. append method has the following syntax. The append method has the following syntax.

alist.append(x)

Inserts the single object x at the end of alist, changing the list in-place.


lst = [1, 2, 3] 
lst.append(4) 
print lst 

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary