OneBite.Dev - Coding blog in a bite size

compare two strings in python

Code snippet on how to compare two strings in python

  str1 = "PHP"
  str2 = "Python"
 
  if str1 == str2:
    print("Strings are equal")
  else:
    print("Strings are not equal")

This code is used to compare two strings. First, two strings are declared and initialized to “PHP” and “Python” respectively. Next, an if statement is used to check if the two strings are equal or not. If the strings are equal, it will print “Strings are equal” and if the strings are not equal then it will print “Strings are not equal”.

python