How to Append an Element to a List in Python
In this tutorial, we will program 'How to Append an Element to a List in Python'. We will learn how to add an element to a list in Python. The main goal here is to create a safe way to store temporary data that can be sent to a working database. I will provide a sample program to demonstrate the actual coding of this tutorial.
This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for appending an element to a list. I will do my best to provide you with the easiest method of appending any element to a list. So, let's start with the coding.
Getting Started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Creating Main Function
This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.- my_list = []
- print("\n\n=============== Append an Element to a List ===============\n\n")
- while True:
- ret=False
- my_input = input("Enter a string: ")
- my_list.append(my_input)
- print(my_list)
- opt = input("\nDo you want to append another string? (Yes/No): ");
- print("\n")
- if opt.lower() == "yes":
- ret=True
- elif opt.lower() == "no":
- ret=False
- print("Exiting Program...")
- else:
- print("Please enter Yes or No\n")
- break
- if ret == False:
- continue
In the provided code, we simply enclosed the code with a while loop to allow for continuous execution of the program. This code is very simple and easy to do; you just append the inputs into an array list using the append function.
Output:

The How to Append an Element to a List in Python source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Append an Element to a List in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for Python Language