Python program to check two strings are equal or not

Python program to check if two strings are the same(case sensitivity)

In this tutorial, we are going to learn writing a python program to check if two given strings given input by the user are the same or not.

Problem Statement

For any two input strings, we have to check if strings are same or not.

For example:

Case1: If the user has given the input string ‘Quescol’ as the first string and ‘Quescol’ as the second string,

The output should be ‘Both strings are same’.

Case2: If the user input the string ‘Quescol’ as the first string and ‘quescol’ as the second string,

The output should be ‘Both strings are not same’.

Case3: If the user input the string ‘Quescol’ as the first string and ‘website’ as the second string,

The output should be ‘Both strings are not same’.

Our logic to check if two strings are the same(case sensitivity)

  • Firstly, we need to take two strings as input from the user using the input() function.
  • Then, compare the strings using the comparison operator. If it returns true then the two strings are the same.

Algorithm to check if two strings are the same(case sensitivity)

Step1:  Start

Step2:   Take two strings as input from the user.

Step3: if string_1 == string_2:

                 print strings are equal

            else:

                print strings are equal

Step4: Stop

Python code to check if two strings are the same(case sensitivity)

Output :

Explanation:

In this example, the first string is taken as ‘Quescol’ and the second string is ‘quescol’, according to case sensitivity, the capital letter and small letter alphabet are considered as different, so according to the output generated ‘The strings are not same’ is correct.