Python (Scripting) - Append values to the end of a list

by
Jeremy Canfield |
Updated: November 06 2023
| Python (Scripting) articles
append can be used to append values to the end of a list in Python. For example, let's say you have the following.
#!/usr/bin/python3
fruits = []
print(f"fruits before append = {fruits}")
fruits.append("apple")
fruits.append("banana")
fruits.append("orange")
fruits.append("grapes")
print(f"fruits after append = {fruits}")
Running this script should output the following.
fruits before append = []
fruits after append = ['apple', 'banana', 'orange', 'grapes']
You can loop through the list.
for x in fruits:
print(x)
Which should print the following.
apple
banana
orange
grapes
kiwi
Did you find this article helpful?
If so, consider buying me a coffee over at