1. Home
  2. Python
  3. Python Examples
  4. Python – Compare Two Strings

Python – Compare Two Strings

Check If Two Strings Are Equal using Python

Use == operator to test if two given strings are equal or not. You can use != as not equal to operator. It returns false if string matches.

Example

In this example, we initialize two variable with sting and compare if both stings are equal or not.

Output:

Equal

Another Example

Here is another sample Python program which will prompt user to enter a strings. Then compare the input string with another predefined string.

Tags , ,