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

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 076517 in the box below so that we can be sure you are a human.