How to Concatenate Two List in Terminal using Python

In this tutorial, we’ll learn how to program "How to Concatenate Two Lists in Python." The objective is to safely merge two lists into a new, combined list. This tutorial will demonstrate the process of using concatenation to achieve the merging of lists effectively. A sample program will be provided to guide you through the implementation. So, let’s get started!

This topic is simple to understand. Just follow the instructions I provide, and you’ll be able to complete it with ease. The program I’ll demonstrate will show you the correct way to concatenate two list. I’ll also include a straightforward and efficient method to achieve this effectively. So, let’s start 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.
  1. list_1 = [1, 'a', 2]
  2. list_2 = [3, 4, 'b']
  3.  
  4. while True:
  5.     print("\n================= Concatenate Two List =================\n\n")
  6.  
  7.     list_joined = list_1 + list_2
  8.  
  9.     print("List 1: ", list_1)
  10.    
  11.     print("\nList 2: ", list_2)
  12.  
  13.     print("\nNew List: ",list_joined)
  14.  
  15.     opt = input("\nDo you want to try again?(yes/no): ")
  16.  
  17.     if opt.lower() == 'yes':
  18.         ret=False
  19.     elif opt.lower() == 'no':
  20.         ret=True
  21.         print("Exiting program....")
  22.     else:
  23.         print("Please enter yes/no:")
  24.         break
  25.  
  26.     if ret == False:
  27.         continue

This program demonstrates how to concatenate two lists in Python. The predefined list_1 contains [1, 'a', 2], and list_2 contains [3, 4, 'b']. By using the + operator, it creates a new combined list list_joined. The program displays the original lists and the concatenated result. Users can choose to repeat the operation or exit the program based on their input.

Output:

There you have it we successfully created How to Concatenate Two 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

Python Tutorials

Add new comment