Python List: append() method
append() method
The append() method is used to add an item to the end of a list.
Visual Explanation:


Syntax:
list.append(item)
Parameter:
- item - Add an item (number, string, list, etc.) at the end of the list.
Equivalent Command of append() method:
a[len(a):] = [x]
Example: Add an element to a list
# colors list
colors = ['Red', 'Green', 'Black']
print("Original list:",colors)
print("Add 'White' to the list:")
colors.append('White')
print("New list:",colors)
Output:
Original list: ['Red', 'Green', 'Black'] Add 'White' to the list: New list: ['Red', 'Green', 'Black', 'White']
Example 2: Adding list to a list
# colors list
colors = ['Red', 'Green', 'Black']
nums = [1, 2, 3]
print("Original lists:")
print(colors)
print(nums)
print("Append nums to colors:")
colors.append(nums)
print("New list:",colors)
Output:
Original lists: ['Red', 'Green', 'Black'] [1, 2, 3] Append nums to colors: New list: ['Red', 'Green', 'Black', [1, 2, 3]]
Python Code Editor:
Previous: Python List Methods home page
Next: Python List clear() Method.
Test your Python skills with w3resource's quiz
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join