1 00:00:00,480 --> 00:00:01,170 Welcome back. 2 00:00:01,680 --> 00:00:07,230 In this video, I want to talk about the idea of Truthy and falsey. 3 00:00:08,970 --> 00:00:15,750 What do they mean, and you'll hear this a lot in Python programming, you see up until now you've used 4 00:00:15,750 --> 00:00:17,940 booleans here as Valdés. 5 00:00:18,300 --> 00:00:22,560 So it was really easy, if true and true, then run this code. 6 00:00:23,390 --> 00:00:26,450 But Python can do other things as well. 7 00:00:26,480 --> 00:00:34,820 For example, if this was five and this was let's say hello, what do you think will happen here in 8 00:00:34,820 --> 00:00:35,510 our program? 9 00:00:35,930 --> 00:00:37,370 Well, if I click, run. 10 00:00:39,620 --> 00:00:42,110 You are old enough to drive and you have a license. 11 00:00:42,500 --> 00:00:44,090 Is that what you expected? 12 00:00:45,620 --> 00:00:52,960 And this is because what Python does underneath the hood is actually convert these to booleans for you, 13 00:00:53,690 --> 00:01:01,340 so it's almost as if it is doing this remember type conversion where converting the type. 14 00:01:02,270 --> 00:01:09,020 To Bolian, as soon as we get to this if statement, because Python is saying, hey, I want true or 15 00:01:09,020 --> 00:01:13,620 false, I don't care what is all this, I don't care what is license's, just give me true or false. 16 00:01:13,760 --> 00:01:17,240 So I know whether to do this or to go to the else block. 17 00:01:18,660 --> 00:01:27,190 Now, if I was to just print let's do this here, let's do print Bolian Hello. 18 00:01:28,140 --> 00:01:32,900 And then finally print Bolian five. 19 00:01:33,060 --> 00:01:33,930 Let's see what we get. 20 00:01:36,230 --> 00:01:45,500 We get true, true, and this is what we call a truthy value in Python, that is it's a Truthy value 21 00:01:45,500 --> 00:01:51,800 because if we run the Bolian type conversion on it, it evaluates into true. 22 00:01:52,610 --> 00:01:54,020 What's a falsey value? 23 00:01:54,320 --> 00:02:00,260 Well, if I do zero and if I do, let's say, an empty string and I click run. 24 00:02:01,690 --> 00:02:09,910 Those are falsie, that is it's not actually false, but it is false because if we run bullion on it 25 00:02:09,910 --> 00:02:14,880 to Python, it's going to say, oh, this is false and zero, that's false. 26 00:02:14,890 --> 00:02:16,900 And that kind of makes sense, right? 27 00:02:18,050 --> 00:02:24,080 And if you actually go to stack overflow, if you've never seen Stack overflow before, if you ever 28 00:02:24,080 --> 00:02:31,400 have programming questions and you're Googling them, usually the top five answers will contain either 29 00:02:31,400 --> 00:02:33,940 one or two stack overflow answers. 30 00:02:33,950 --> 00:02:38,960 And basically what happens is people ask questions like what is truth and falsity in Python? 31 00:02:39,140 --> 00:02:40,880 And you get answers. 32 00:02:41,330 --> 00:02:47,330 So you can see over here that it has four answers and you usually look for the checkmark, which means 33 00:02:47,330 --> 00:02:52,700 that this is a verified answer and means that, hey, this question owner has accepted it as the best 34 00:02:52,700 --> 00:02:53,010 answer. 35 00:02:53,030 --> 00:02:56,760 So the person who asked this question just said, yeah, this is the right answer. 36 00:02:56,780 --> 00:02:57,530 This is the best one. 37 00:02:57,800 --> 00:02:59,570 But you also have other people voting. 38 00:02:59,570 --> 00:03:03,410 So you can see that this answer received 46 marks. 39 00:03:03,410 --> 00:03:09,080 And although it was marked as the correct answer by the user, maybe somebody else came along later 40 00:03:09,080 --> 00:03:11,450 on and gave an even better answer. 41 00:03:11,480 --> 00:03:16,910 So now we have one hundred and twenty three upvotes and you see that this answer is a lot better. 42 00:03:17,420 --> 00:03:21,110 All values are considered Truthy except for the following. 43 00:03:22,290 --> 00:03:30,150 So you can actually see here that in Python, these values are considered falsey, you can see zero 44 00:03:30,150 --> 00:03:30,560 here. 45 00:03:30,570 --> 00:03:35,850 You can see an empty string here and then there's a few other ones empty set. 46 00:03:36,060 --> 00:03:40,530 You have an empty dictionary, empty list, empty tuple. 47 00:03:40,860 --> 00:03:42,090 You have decimals. 48 00:03:42,540 --> 00:03:44,100 You have things like fractions. 49 00:03:44,310 --> 00:03:46,830 You have zero point zero falsies. 50 00:03:46,830 --> 00:03:49,530 That and also none is falsey. 51 00:03:50,250 --> 00:03:53,130 So that if I type in none here. 52 00:03:54,620 --> 00:03:55,910 That's false to. 53 00:03:57,190 --> 00:04:01,960 Now, you don't need to memorize this because most of the time it it makes sense, right? 54 00:04:02,170 --> 00:04:04,980 But it helps us do conditional logic very nicely. 55 00:04:05,470 --> 00:04:16,270 For example, let's remove this and let's say that we have a user and this user has to have a password 56 00:04:16,870 --> 00:04:18,430 and a username. 57 00:04:20,990 --> 00:04:29,270 If let's say the username is Johnny and the password is one, two, three. 58 00:04:30,920 --> 00:04:37,880 Well, instead of me saying, hey, if this user has a password and username and we're not checking 59 00:04:38,000 --> 00:04:43,100 if the username exists or password exists, we just want to make sure, hey, did this person fill out 60 00:04:43,100 --> 00:04:46,240 the form and did they try to submit a username and password? 61 00:04:46,550 --> 00:04:50,390 I can just simply say password and username. 62 00:04:51,920 --> 00:04:57,140 And I don't have to worry about converting this to a bullion or anything like that, because if password 63 00:04:57,140 --> 00:05:04,880 and username exist, then try to lock them in and you see that it reads a lot nicer because each one 64 00:05:04,880 --> 00:05:08,390 of these get evaluated into a truthy and falsey value. 65 00:05:08,870 --> 00:05:14,570 It's a nice little feature to keep Python well, nice and simple and reading like English. 66 00:05:15,740 --> 00:05:17,510 I'll see in the next video by.