1 00:00:00,000 --> 00:00:11,160 So, there are two more useful operators 2 00:00:11,160 --> 00:00:13,665 for producing Boolean values. 3 00:00:13,665 --> 00:00:18,995 First, we're going to go over in and then we're going to go over its opposite not in. 4 00:00:18,995 --> 00:00:24,735 So, in checks to see if the thing on the left is a member of the thing on the right. 5 00:00:24,735 --> 00:00:26,640 So for example here, 6 00:00:26,640 --> 00:00:29,970 suppose that we have a string apple and we want to 7 00:00:29,970 --> 00:00:33,795 check if some substring is contained in that string. 8 00:00:33,795 --> 00:00:36,770 So, the value of this expression is going to be true, 9 00:00:36,770 --> 00:00:40,340 because the character p is an apple. 10 00:00:40,340 --> 00:00:43,370 The value of this expression is going to be false, 11 00:00:43,370 --> 00:00:46,430 because the character i is not an apple. 12 00:00:46,430 --> 00:00:49,640 The value of this expression is going to be true, 13 00:00:49,640 --> 00:00:53,675 because the substring AP is an apple. 14 00:00:53,675 --> 00:00:57,275 And the value of this expression is going to be false, 15 00:00:57,275 --> 00:00:59,585 because PA is not an apple. 16 00:00:59,585 --> 00:01:03,845 So, I should get true, false, true, false. 17 00:01:03,845 --> 00:01:09,815 So, if I print out is a in the string a then I should get true, 18 00:01:09,815 --> 00:01:13,160 because yes, even though these two things are the same, 19 00:01:13,160 --> 00:01:16,235 technically this is inside of this. 20 00:01:16,235 --> 00:01:19,045 Same thing with if I spell out apple. 21 00:01:19,045 --> 00:01:23,435 So, the value of both of these expressions will be true. 22 00:01:23,435 --> 00:01:29,180 Somewhat weirdly, if I check to see if an empty string is contained in any other string, 23 00:01:29,180 --> 00:01:30,665 then I'm going to get true. 24 00:01:30,665 --> 00:01:34,320 So, is this empty string inside of the string a? 25 00:01:34,320 --> 00:01:36,805 It's debatable what the answer should be, 26 00:01:36,805 --> 00:01:40,625 but the way that Python evaluates this expression I get true. 27 00:01:40,625 --> 00:01:44,675 So, if I check to see if this empty string is in the string apple, 28 00:01:44,675 --> 00:01:47,200 I'm going to get true for this as well. 29 00:01:47,200 --> 00:01:51,170 Now, the opposite of in is not in. 30 00:01:51,170 --> 00:01:55,400 So, if I check to see if something is not in another string, 31 00:01:55,400 --> 00:01:58,430 then I'm going to get true if it's not in that string. 32 00:01:58,430 --> 00:02:01,660 So, x is not in apple. 33 00:02:01,660 --> 00:02:05,900 So, the value of this overall expression is going to be 34 00:02:05,900 --> 00:02:10,460 true because the string apple doesn't contain the character x. 35 00:02:10,460 --> 00:02:14,630 So, somewhat confusingly, this not has 36 00:02:14,630 --> 00:02:20,230 the same spelling as something like not Boolean expression, 37 00:02:20,230 --> 00:02:23,585 but these are entirely different things. 38 00:02:23,585 --> 00:02:28,415 They have the same function which is reversing the value of the Boolean expression, 39 00:02:28,415 --> 00:02:31,820 so I'm saying not B is going to be true if B is 40 00:02:31,820 --> 00:02:36,635 false in not in is going to be true if this is not in it, 41 00:02:36,635 --> 00:02:41,405 but to Python, there are different kinds of expressions. 42 00:02:41,405 --> 00:02:47,615 So, I just want to also illustrate that in also works with lists. 43 00:02:47,615 --> 00:02:52,880 So, here if I check to see if this item is in this list, 44 00:02:52,880 --> 00:02:56,450 I'm going to get the value false because it's 45 00:02:56,450 --> 00:03:00,230 checking to see is there an item in this list, 46 00:03:00,230 --> 00:03:03,485 whose value is just the string A, 47 00:03:03,485 --> 00:03:06,710 even though I have some strings that happen to contain 48 00:03:06,710 --> 00:03:10,780 As there's no item whose value is equal to A, 49 00:03:10,780 --> 00:03:13,950 so I get false for this expression. 50 00:03:13,950 --> 00:03:17,290 That's all for now until next time.