Google News
logo
Python Program to Add an item to the end of a list
To add an item to the end of a list in Python, you can use the `append()` method. Here's an example program :
Program :
my_list = [1, 2, 3, 4, 5]
print("Original list:", my_list)

# Append an item to the end of the list
my_list.append(6)
print("List after appending an item:", my_list)
Output :
Original list: [1, 2, 3, 4, 5]
List after appending an item: [1, 2, 3, 4, 5, 6]
In the above program, we first create a list `my_list` containing five items. Then we use the `append()` method to add an item `6` to the end of the list. The updated list is then printed to the console.