1 00:00:00,000 --> 00:00:03,300 In Python, a variable can have absolutely nothing in it, 2 00:00:03,300 --> 00:00:05,500 and that is called a 'NoneType'. 3 00:00:05,500 --> 00:00:06,500 That's a data type. 4 00:00:06,520 --> 00:00:09,180 It's a proper one. But there's just nothing in it. 5 00:00:09,300 --> 00:00:15,300 So if we said that I'm about to make a grocery list, but 6 00:00:15,300 --> 00:00:16,800 I don't have any items in it yet. 7 00:00:17,340 --> 00:00:20,410 I could either do, you know, list is equal to an empty list, 'lst = []', 8 00:00:20,770 --> 00:00:22,090 or I could say, "You know what, 9 00:00:22,100 --> 00:00:24,760 I haven't even started my list yet, so it could be None. 10 00:00:24,980 --> 00:00:27,770 Now that gets a little confusing with the word 'ls' and None, 11 00:00:27,780 --> 00:00:29,210 so let's do something else. 12 00:00:29,420 --> 00:00:31,910 Let's say how many sports do you play? 13 00:00:31,920 --> 00:00:33,770 'sports = None'. 14 00:00:33,780 --> 00:00:35,030 Let's say I play no sports. 15 00:00:35,180 --> 00:00:37,700 I can do 'type(sports)'. 16 00:00:38,180 --> 00:00:41,930 I can also, fun fact, do 'type(None)', 17 00:00:42,320 --> 00:00:45,050 it'll show me the exact same thing, because this is really 18 00:00:45,060 --> 00:00:46,820 just a pointer to whatever that value is. 19 00:00:47,000 --> 00:00:50,300 Now, 'None' in itself is nothing. 20 00:00:50,300 --> 00:00:54,700 If we cast this to a Boolean, we could do 'bool(None)', 21 00:00:54,720 --> 00:00:56,150 we'll get to see, it's False. 22 00:00:56,150 --> 00:00:58,850 Always evaluates as False because there's nothing in there. 23 00:00:58,880 --> 00:01:01,130 Now let's see if we can do anything with this. 24 00:01:01,190 --> 00:01:06,620 'sport.', and I hit tab, and nothing's happening. Literally 25 00:01:06,629 --> 00:01:08,030 cannot do anything with it. 26 00:01:08,040 --> 00:01:10,490 So you're probably thinking, "Kalob, where is this useful? 27 00:01:10,500 --> 00:01:13,700 If I can't do anything with this and its value is nothing, 28 00:01:13,980 --> 00:01:15,210 where is this useful? 29 00:01:15,220 --> 00:01:18,810 Well, down the road and we'll explore this much further on, 30 00:01:18,990 --> 00:01:21,330 but down the road you could say something along the lines 31 00:01:21,340 --> 00:01:26,590 of 'if sports is None', do something and what this is saying, 32 00:01:26,600 --> 00:01:28,960 we'll learn more about this in depth, 33 00:01:28,970 --> 00:01:32,440 but what this is saying is if 'sports' is None, it is exactly 34 00:01:32,470 --> 00:01:34,850 None, then do something, 35 00:01:34,860 --> 00:01:37,710 otherwise maybe do something else. 36 00:01:37,720 --> 00:01:41,400 Now, where this gets really useful, especially in cases like 37 00:01:41,410 --> 00:01:45,220 web development, you could say up here, '?name 38 00:01:45,230 --> 00:01:48,700 =', and you could check to see what that value is, 39 00:01:48,710 --> 00:01:50,770 and by default you would say it's None. 40 00:01:51,070 --> 00:01:54,310 So an example using a dictionary, not quite the same thing 41 00:01:54,320 --> 00:01:58,650 as using a query string from a URL, but a dictionary, 42 00:01:58,650 --> 00:02:03,400 so a 'dict = ' 43 00:02:03,440 --> 00:02:06,110 And let's not use the keyword. 44 00:02:06,110 --> 00:02:10,100 'dict', let's just use the variable called 'd'. 45 00:02:10,100 --> 00:02:12,100 So in here we've got a dictionary. 46 00:02:12,300 --> 00:02:17,300 And if I wanted to get('thing'), this is going to return 'thing2' for me. 47 00:02:17,500 --> 00:02:20,320 But what if I'm trying to 'get' something that doesn't exist? 48 00:02:20,540 --> 00:02:24,080 I'm trying to 'get('something_else')', and there's a typo in 49 00:02:24,090 --> 00:02:25,010 there, but I don't care. 50 00:02:25,140 --> 00:02:26,310 There's nothing. 51 00:02:26,320 --> 00:02:28,710 Now let's put this into a variable. 52 00:02:28,940 --> 00:02:33,570 Let's put this into a throwaway variable called ''a, and let's 53 00:02:33,580 --> 00:02:36,570 'print(a)'. Yeah, there's nothing there. 54 00:02:36,580 --> 00:02:39,590 'type(a)'. It's a NoneType. 55 00:02:39,890 --> 00:02:44,490 And so by default, this second parameter is the default, 56 00:02:44,600 --> 00:02:45,600 is going to be None. 57 00:02:45,660 --> 00:02:49,470 Now what we can say here, is if it's 'None', then we can say 58 00:02:49,500 --> 00:02:57,500 'if a is None, print("Did not find something_else")'. 59 00:02:58,210 --> 00:03:01,520 And just like that, we're able to check to see if there was 60 00:03:01,530 --> 00:03:05,330 an item, a key in this dictionary, and if there wasn't, 61 00:03:05,340 --> 00:03:06,440 well, then there's 'None', 62 00:03:06,450 --> 00:03:09,640 and we can actually say if there was 'None', then do something. 63 00:03:09,650 --> 00:03:11,260 So that's a 'NoneType' 64 00:03:11,410 --> 00:03:14,890 in a nutshell. It's actually not a very useful feature because 65 00:03:14,900 --> 00:03:17,870 you can use pretty much anything else if you wanted to, you 66 00:03:17,880 --> 00:03:19,100 wouldn't have to use 'None'. 67 00:03:19,110 --> 00:03:23,210 You could use an empty string as that would result in a False 68 00:03:23,210 --> 00:03:24,140 if statement as well, 69 00:03:24,140 --> 00:03:25,100 False Boolean. 70 00:03:25,100 --> 00:03:29,540 Same with an empty dictionary or a tuple or a list. 71 00:03:29,870 --> 00:03:31,670 You could use pretty much anything else. 72 00:03:31,680 --> 00:03:37,300 But as those are usually reserved for actual specific tasks, 73 00:03:37,530 --> 00:03:41,320 this one isn't, this one's just saying, "Hey, there's nothing 74 00:03:41,330 --> 00:03:43,520 there". And in this case, that's perfect. 75 00:03:43,530 --> 00:03:45,110 We wanted to see if there was nothing there. 76 00:03:45,160 --> 00:03:48,250 You don't really need to know or do anything with this lesson, 77 00:03:48,440 --> 00:03:53,060 but it's good to know that 'None' and 'NoneType', or rather just 78 00:03:53,070 --> 00:03:53,450 'NoneType', 79 00:03:53,510 --> 00:03:55,340 but we use the word 'None'. 80 00:03:55,500 --> 00:03:58,700 'NoneType' is a data type in Python.