To compare two strings in python, you have to ask from user to enter any two string to check whether the two string are equal or not as shown in the program given below.
Following python program ask from user to enter first and second string to compare the given two string:
# Python Program - Compare Two Strings while True: print("Enter 'x' for exit.") string1 = input("Enter string1: ") string2 = input("Enter string2: ") if string1 == 'x': break else: if string1 == string2: print("Both Strings are Equal.\n") else: print("Strings are Not Equal.\n")
Here is the sample run of the above Python program to demonstrate how to compare two string:
You may also like to learn or practice the same program in other popular programming languages: