Compare two Strings in python

python program to get two strings and check whether both are equal

Sample Input 1 :

MARK MAKE

Sample Output 1 :

Not Equal

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

				
			
					
s1=input("Enter first String:")
s2=input("Enter first String:")
if(len(s1)==len(s2)):
    for i in range(0,len(s1)):
        if(s1[i]!=s2[i]):
            print("Not Equal")
            break
    else:
        print("equal")
else:
    print("Not Equal")
    
        
    
      

			
				
			

Program Explanation

if the length of two strings are not equal then strings are not equal else, visit each location of in strings and compare the characters in s1 and s2.

if all the characters are s1 and s2 are equal then the strings are equal else not equal.

Comments