How to Print All Letters Present in Both Strings in Python

In this tutorial, we will learn how to program "How to Print All Letters Present in Both Strings in Python." The objective is to efficiently identify and print all the letters that appear in both given strings. This tutorial will guide you step by step through the entire process, demonstrating how to compare strings and extract the common characters. By the end of this tutorial, you will have a clear understanding of how to implement this task effectively in Python, helping you strengthen your problem-solving abilities and coding skills.

This topic is straightforward to understand. Just follow the instructions provided, and you will be able to complete it with ease. The program demonstrated will guide you step by step through the process of printing all the letters present in both strings. So, let’s dive into the coding process!

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. while True:
  2.     print("\n============== Print All Letters Present in Both Strings ==============\n")
  3.  
  4.     s1=input("Enter first string:")
  5.     s2=input("Enter second string:")
  6.     a=list(set(s1)|set(s2))
  7.     print("The letters are:")
  8.     for i in a:
  9.         print(i)
  10.  
  11.     opt = input("\nDo you want to try again?(yes/no): ")
  12.            
  13.     if opt.lower() == 'yes':
  14.         ret=False
  15.     elif opt.lower() == 'no':
  16.         ret=True
  17.         print("Exiting program....")
  18.     else:
  19.         print("Please enter yes/no:")
  20.         break
  21.  
  22.     if ret == False:
  23.         continue

This Python program repeatedly asks the user to input two strings, then finds and prints all the unique letters that are present in either of the two strings by using set operations, and allows the user to repeat or exit the process.

Output:

There you have it we successfully created How to Print All Letters Present in Both Strings 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