WEBVTT 1 00:00:00.130 --> 00:00:01.860 Hi guys, and welcome back. 2 00:00:01.860 --> 00:00:05.100 In this video we're going to learn about booleans. 3 00:00:05.100 --> 00:00:09.260 In Python, we've got true and false values, 4 00:00:09.260 --> 00:00:11.810 and they're used to make decisions. 5 00:00:11.810 --> 00:00:16.440 For example; is the user's age over 35? 6 00:00:16.440 --> 00:00:18.920 That could be a comparison that 7 00:00:18.920 --> 00:00:21.520 we evaluate to True or False. 8 00:00:21.520 --> 00:00:25.440 In Python, the keywords are True, with a capital T 9 00:00:25.440 --> 00:00:28.200 and False with a capital F. 10 00:00:28.200 --> 00:00:29.850 Here, I've created two variables, 11 00:00:29.850 --> 00:00:34.480 one of them called truthy and that has a True value 12 00:00:34.480 --> 00:00:37.840 and one called falsy and that has a False value. 13 00:00:37.840 --> 00:00:41.350 But, on their own, this is kind of pointless 14 00:00:41.350 --> 00:00:44.870 because what can you use True for, 15 00:00:44.870 --> 00:00:48.350 there's not much use for just something True. 16 00:00:48.350 --> 00:00:51.490 But, when you've got a number, 17 00:00:51.490 --> 00:00:54.950 you can then say whether A's over age 18 00:00:54.950 --> 00:00:58.890 and type age greater than or equal to 18. 19 00:00:58.890 --> 00:01:01.950 So here we've got our first boolean comparison. 20 00:01:01.950 --> 00:01:05.920 We've got the variable, then we've got an equal sign 21 00:01:05.920 --> 00:01:08.560 which means that this variable is going 22 00:01:08.560 --> 00:01:11.533 to be a name for this value here. 23 00:01:12.390 --> 00:01:16.830 And the value is age greater than or equal to 18. 24 00:01:16.830 --> 00:01:20.400 This here is a boolean comparison 25 00:01:20.400 --> 00:01:23.650 and it evaluates to True because 20 26 00:01:23.650 --> 00:01:26.440 is greater than or equal to 18. 27 00:01:26.440 --> 00:01:30.683 So doing this here is exactly the same as doing True. 28 00:01:31.780 --> 00:01:33.960 We can have A's under age, which means 29 00:01:33.960 --> 00:01:35.623 age is less than 18, 30 00:01:36.750 --> 00:01:40.330 and here this would be False because age is 20 31 00:01:40.330 --> 00:01:44.623 so 20 is not less than 18, this would be False. 32 00:01:46.060 --> 00:01:49.990 Do not that I'm not doing age less than or equal to 18 33 00:01:49.990 --> 00:01:53.040 as when you are 18 you are allegedly over age 34 00:01:53.040 --> 00:01:56.493 in most countries, so this one has to be less than only. 35 00:01:57.850 --> 00:02:00.400 Finally, you can also check whether A is 20 36 00:02:00.400 --> 00:02:04.550 for example, and type age equal equal 20. 37 00:02:04.550 --> 00:02:06.450 Now, this can get a bit confusing because 38 00:02:06.450 --> 00:02:09.021 you now have three equal signs in one line. 39 00:02:09.021 --> 00:02:11.237 When you have a single equal sign, 40 00:02:11.237 --> 00:02:13.720 that is used for assignment. 41 00:02:13.720 --> 00:02:15.643 What it says is this value here, 42 00:02:15.643 --> 00:02:18.340 we're gonna give it this name. 43 00:02:18.340 --> 00:02:21.090 So, we will calculate the value first, 44 00:02:21.090 --> 00:02:24.280 and then put the name and give it to it. 45 00:02:24.280 --> 00:02:26.950 Two equal signs is not used for assignment; 46 00:02:26.950 --> 00:02:28.720 it is used for comparison. 47 00:02:28.720 --> 00:02:31.900 What it means is exactly equal to. 48 00:02:31.900 --> 00:02:34.560 So what it's saying is, is the age variable 49 00:02:34.560 --> 00:02:36.970 exactly equal to 20? 50 00:02:36.970 --> 00:02:38.220 And the answer is yes. 51 00:02:38.220 --> 00:02:41.283 So this whole thing here actually evaluates to True. 52 00:02:42.580 --> 00:02:45.300 Other symbols that you can use are of course 53 00:02:45.300 --> 00:02:47.610 greater than on it's own, and less than 54 00:02:47.610 --> 00:02:49.930 or equal to like that. 55 00:02:49.930 --> 00:02:52.240 Let's create a simple programme that will ask 56 00:02:52.240 --> 00:02:54.748 the user for a number and then we will tell them 57 00:02:54.748 --> 00:02:58.000 whether it matches our magic number. 58 00:02:58.000 --> 00:03:01.350 So we will have our number, which is five, 59 00:03:01.350 --> 00:03:03.513 and then we will ask the user for a number, 60 00:03:06.170 --> 00:03:08.159 like that, and then we will say 61 00:03:08.159 --> 00:03:12.163 my number equal to user number. 62 00:03:15.980 --> 00:03:18.330 So, as long as they enter five, 63 00:03:18.330 --> 00:03:21.040 this will be True, and if they enter anything 64 00:03:21.040 --> 00:03:23.950 else, then it is False. 65 00:03:23.950 --> 00:03:26.110 To make this a little bit better, 66 00:03:26.110 --> 00:03:28.800 you can create a new variable, which has the value 67 00:03:28.800 --> 00:03:31.323 of whether it matches or not. 68 00:03:32.470 --> 00:03:35.373 And then you can use an F string to say, 69 00:03:36.467 --> 00:03:40.463 "You got it right" matches. 70 00:03:42.800 --> 00:03:45.960 And then if we run this, and we type five, 71 00:03:45.960 --> 00:03:48.023 you say, "You got it right" True. 72 00:03:49.110 --> 00:03:51.597 Later on in the course, we're going to learn how to say, 73 00:03:51.597 --> 00:03:54.220 "You got it right" or "You got it wrong". 74 00:03:54.220 --> 00:03:56.330 But at the moment we really can't do that. 75 00:03:56.330 --> 00:03:58.410 We need something called an 'if statement' 76 00:03:58.410 --> 00:03:59.500 in order to be able to do that 77 00:03:59.500 --> 00:04:00.560 and we're going to learn about that 78 00:04:00.560 --> 00:04:02.450 in the next section. 79 00:04:02.450 --> 00:04:04.850 But for now, you have the ability to get 80 00:04:04.850 --> 00:04:07.100 information from the user, and compare it to 81 00:04:07.100 --> 00:04:09.280 something that you already have. 82 00:04:09.280 --> 00:04:11.920 And then determine one thing or another, 83 00:04:11.920 --> 00:04:14.073 whether something is True or False. 84 00:04:15.120 --> 00:04:16.650 In the next video, we will learn more 85 00:04:16.650 --> 00:04:18.300 about working with booleans, 86 00:04:18.300 --> 00:04:21.150 and making our programmes much more flexible. 87 00:04:21.150 --> 00:04:22.100 I'll see you there.