for loop append list Python | Example code

You can append a list in for loop, Use the list append() method to append elements to a list while iterating over the given list.

Append list in a for loop

Python simple example code.

data = ["a", "b", "c", "d"]

results = []
print(results)

for x in data:
    results.append(x)

print(results)

Output:

for loop append list Python

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

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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


Leave a Reply

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