1 00:00:00,950 --> 00:00:02,820 - [Instructor] In this video, I'd like to demonstrate 2 00:00:02,820 --> 00:00:05,620 the comparison operators for strings. 3 00:00:05,620 --> 00:00:08,010 But first, I'd like to just remind you 4 00:00:08,010 --> 00:00:11,420 that when you're doing string comparisons in Python, 5 00:00:11,420 --> 00:00:14,270 it's lexicographical comparisons, 6 00:00:14,270 --> 00:00:16,900 that is the underlying numeric values 7 00:00:16,900 --> 00:00:19,920 of the characters are what are being compared. 8 00:00:19,920 --> 00:00:24,810 So you may recall that we introduced the ord function 9 00:00:24,810 --> 00:00:27,090 previously, the built-in function ord, 10 00:00:27,090 --> 00:00:29,150 which simply returns for a character 11 00:00:29,150 --> 00:00:31,260 the corresponding numeric value. 12 00:00:31,260 --> 00:00:33,360 So here we have the capital letter A 13 00:00:33,360 --> 00:00:34,870 and the lowercase letter a 14 00:00:34,870 --> 00:00:36,260 and we just wanted to show you 15 00:00:36,260 --> 00:00:39,120 that the capital letter has a smaller value 16 00:00:39,120 --> 00:00:40,610 than the lowercase letter, 17 00:00:40,610 --> 00:00:43,830 because that's going to affect the comparisons 18 00:00:43,830 --> 00:00:47,190 that we're going to do in the next several expressions. 19 00:00:47,190 --> 00:00:49,910 So you can compare any two strings 20 00:00:49,910 --> 00:00:53,560 using the comparison operators, the equality, 21 00:00:53,560 --> 00:00:56,520 inequality, less than, less than or equal, 22 00:00:56,520 --> 00:00:59,330 greater than, or greater than or equal to operators. 23 00:00:59,330 --> 00:01:02,500 In this case, yes it's the same word, 24 00:01:02,500 --> 00:01:04,890 but one of them is spelled with an uppercase letter 25 00:01:04,890 --> 00:01:08,470 and one with a lowercase letter, so these are not equal. 26 00:01:08,470 --> 00:01:10,310 And of course, correspondingly, 27 00:01:10,310 --> 00:01:12,800 if I change that to a not equals operator, 28 00:01:12,800 --> 00:01:14,950 we will, in fact, get true. 29 00:01:14,950 --> 00:01:18,150 Now if I change that operator to a less than sign 30 00:01:18,150 --> 00:01:21,940 because a capital O is less than a lowercase o, 31 00:01:21,940 --> 00:01:25,320 this will be true, and so will, of course, 32 00:01:25,320 --> 00:01:28,530 less than or equal because it's still less than 33 00:01:28,530 --> 00:01:30,090 in that case. 34 00:01:30,090 --> 00:01:32,663 If I change the operator to a greater than sign, 35 00:01:34,400 --> 00:01:38,040 capital O is not greater than lowercase o 36 00:01:38,040 --> 00:01:40,130 in terms of as key values, 37 00:01:40,130 --> 00:01:42,750 so capital a is less than lowercase A, 38 00:01:42,750 --> 00:01:45,880 capital o will be less than lowercase O as well. 39 00:01:45,880 --> 00:01:47,850 Therefore, this will result in false, 40 00:01:47,850 --> 00:01:51,083 as will the greater than or equal operator.