Python Program to Compare Two Strings

« Previous Program Next Program »

Compare Two Strings in Python

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.

Python Programming Code to Compare Two Strings

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':
		if string1 == string2:
			print("Both Strings are Equal.\n")
			print("Strings are Not Equal.\n")

Here is the sample run of the above Python program to demonstrate how to compare two string:

python compare two strings

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test