Lesson goal: Comparing strings considering case

Previous: Comparing strings | Home | Next: Finding Palindromes

In the last lesson you learned how to compare a string to the word "computer." What would happen if the person typed the word "Computer" or "COMPUTER" or "CoMpUtEr"? Should these compare favorably to "computer" as well? It depends if you want it to, but indeed "computer" is not equal to "Computer" or "COMPUTER." You are probably familiar with "case sensitive" passwords online, meaning upper and lower case letters are treated differently; this is the heart of the issue.

If you want to ignore the case of letters in a comparison, you first have to covert your incoming string to all upper or all lower case first. You can do this with the string.lower() or string.upper() functions.

Now you try. Run this code and type in the word computer with different cases, like Computer or COMPUTER.

Type your code here:


See your results here: