Python append() Syntax
The syntax of the append() method is straightforward:
list.append(element)
- list: This is the list to which you want to add the element.
- element: This is the item you want to append to the list. The element can be of any data type—string, integer, float, list, dictionary, etc.
append() does not return a new list; it modifies the existing list by adding the element to its end.
Examples of Append Method in Python
Here are the examples of using append() with their outputs:
1. Appending numbers in a loop:
Python
squares = []
for i in range(1, 5):
squares.append(i ** 2)
print(squares)

You can also try this code with Online Python Compiler
Run Code
Output:
[1, 4, 9, 16]
2. Building a list of student records:
Python
students = []
students.append({"name": "Rahul", "grade": 95})
students.append({"name": "Rohit", "grade": 87})
students.append({"name": "Virat", "grade": 92})
print(students)

You can also try this code with Online Python Compiler
Run Code
Output:
[{'name': 'Rahul', 'grade': 95}, {'name': 'Rohit', 'grade': 87}, {'name': 'Virat', 'grade': 92}]
3. Creating a list of words from a sentence:
Python
sentence = "Python is awesome"
words = []
for word in sentence.split():
words.append(word.upper())
print(words)

You can also try this code with Online Python Compiler
Run Code
Output:
['PYTHON', 'IS', 'AWESOME']
Use of Append in Python
The append method is used in several common scenarios:
1. Building lists dynamically:
user_inputs = []
user_inputs.append("first input")
user_inputs.append("second input")
2. Collecting results:
results = []
for number in range(5):
if number % 2 == 0:
results.append(number)
# results will contain even numbers: [0, 2, 4]
3. Storing processed data:
names = ["rahul", "rohit", "virat"]
capitalized = []
for name in names:
capitalized.append(name.capitalize())
# capitalized will be: ["Rahul", "Rohit", "Virat"]
Advantage of the append() Method
The main advantage of the append() method is its efficiency and ease of use:
- In-place Modification: append() modifies the original list in place, so there’s no need to create a new list each time an item is added.
- Dynamic: append() allows for adding elements to lists dynamically, making it suitable for cases where the number of items may vary.
- Efficient Memory Management: As append() adds to the existing list rather than creating a new one, it is memory-efficient, especially for large datasets.
You can also read about the Multilevel Inheritance in Python and Convert String to List Python.
Check out Escape Sequence in Python
Frequently Asked Questions
What does append() return in Python?
The append() method in Python returns None. It modifies the original list by adding an element to its end without creating or returning a new list.
What is append in List_name?
In Python, List_name.append() means invoking the append() method on List_name, which is a list. It adds the specified element to the end of the list, modifying it in place.
What are the benefits of append()?
append() is efficient and memory-friendly, modifying lists directly without copying. It enables dynamic list-building, ideal for runtime data collection, and helps create lists efficiently with minimal code.
Conclusion
We have seen the append in Python in detail. We have also learnt four built-in structures in Python. I hope you have liked this article.
You can check out our courses on Web development if you wish to build a few projects on your own under the guidance of our Mentors. Also, refer to our Guided Path on Code360 to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, and many more! If you wish to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio!
Also check out - Data Dictionary In Software Engineering
Happy Learning!