Examples of comparing strings
“ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”? No – has to match every character “ABC” < “abc”? Yes – upper case is less than lower case “Bob” ‘R’
More “123 Main” > “99 South” ? Yes, “1” < “9” “ABC” > “ ABC”? No! “ “ comes before anything else! “ABC” “1” “12” < “14”? Yes – “2” < “4” “99” “1” “App” < “Apple”? Yes – the same until the shorter one runs out, shorter one is less
Upper and Lower case How to test a character to see if upper case? In Python, char.isupper() returns True if upper In Python, “A” <= char <= “Z” works too In any language, char >= “A” and char <= “Z” Do NOT use ASCII codes where the characters themselves will do! NO! 65 <= ord(char) <= 91 NO! ord(char) == 32 (same as char == “ “)