Python append to empty list | Example code

  • by

Use Python List append() Method to append to an empty list. This method will append elements (object) to the end of an empty list.

list.append("obj")

You can also use the + operator to concatenate a list of elements to an empty list.

list = list + ["obj"]

How to append to an empty list in Python example

Simple python example code.

Using the List append method

a_list = []

a_list.append("New item")
print(a_list)

Output:

Python append to empty list

Using + operator to concatenate a list

a_list = []

a_list = a_list + [1, 2, 3]

print(a_list)

Output:

[1, 2, 3]

Do comment if you have any doubts and suggestions on this Python list topic.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.