Compare string demo : Compare String « String « Python Tutorial






str1 = 'abc'
str2 = 'lmn'
str3 = 'xyz'
print str1 < str2
print str2 != str3
print str1 < str3 and str2 == 'xyz'








5.4.Compare String
5.4.1.Strings are compared according to their order when sorted alphabetically:
5.4.2.To ignore the difference between uppercase and lowercase letters, use the string methods upper or lower
5.4.3.Case Sensitive Compare
5.4.4.Case In-Sensitive Compare
5.4.5.Compare string demo
5.4.6.cmp() function performs a lexicographic (ASCII value-based) comparison for strings.