Presentation is loading. Please wait.

Presentation is loading. Please wait.

Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?

Similar presentations


Presentation on theme: "Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?"— Presentation transcript:

1 Examples of comparing strings

2 “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’

3 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

4 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 == “ “)


Download ppt "Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?"

Similar presentations


Ads by Google