Comparing strings
You have compared strings with == and != already. Two strings are equal only when they have exactly the same characters, capital letters and spaces included:
>>> "Python" == "python"
False
>>> "yes" == "yes "
False
>>> "cat" != "dog"
TrueAlphabetical order
< and > work on strings too. A string is "less than" another when it comes first in alphabetical order, as in a dictionary:
>>> "apple" < "banana"
True
>>> "cat" > "car"
True
>>> "car" < "cart"
TruePython compares two strings character by character from the start, and the first character that differs decides. "cat" and "car" differ at the third letter, and t comes after r. When one string runs out first, as "car" does next to "cart", the shorter one comes first.
Together with elif, this puts two words in order:
first = input("First word: ")
second = input("Second word: ")
if first < second:
print(f"{first} comes before {second}")
elif first > second:
print(f"{second} comes before {first}")
else:
print("The words are the same")
pear
appleFirst word: pear
Second word: apple
apple comes before pearCapitals and digits
Python's order isn't quite a dictionary's. It compares the codes of the characters, and in them every capital letter comes before every small letter. Letters with marks, such as é, come after all of these. Digits in a string are just characters as well, compared one at a time:
>>> "Zebra" < "apple"
True
>>> "10" < "9"
True
>>> 10 < 9
False"10" comes before "9" because its first character, 1, comes before 9. So compare words written the same way (all in small letters, for example), and convert numbers that the user typed with int before you compare them.