cmp() function performs a lexicographic (ASCII value-based) comparison for strings. : Compare String « String « Python Tutorial






str1 = 'abc'
str2 = 'lmn'
str3 = 'xyz'

print cmp(str1, str2)
print cmp(str3, str1)
print cmp(str2, 'lmn')








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.