1 00:00:00,930 --> 00:00:02,070 Instructor: Welcome back. 2 00:00:02,070 --> 00:00:04,890 Let's talk about our first data type. 3 00:00:04,890 --> 00:00:05,730 And you know what? 4 00:00:05,730 --> 00:00:08,400 Let's do two at the same time. 5 00:00:08,400 --> 00:00:11,100 We have int and floats. 6 00:00:11,100 --> 00:00:15,750 Int stands for integer, as you can see here, 7 00:00:15,750 --> 00:00:20,730 and float stands for a floating point number. 8 00:00:20,730 --> 00:00:21,780 Hmm. 9 00:00:21,780 --> 00:00:23,490 Let's explore that. 10 00:00:23,490 --> 00:00:26,343 First, let's start off with integer. 11 00:00:27,810 --> 00:00:31,740 An integer is, well, a number. 12 00:00:31,740 --> 00:00:36,603 Three or four or five, these are all integers. 13 00:00:37,530 --> 00:00:39,270 In a programming language, 14 00:00:39,270 --> 00:00:43,800 you can use integers to do mathematical operations, 15 00:00:43,800 --> 00:00:47,160 for example 2 + 4. 16 00:00:47,160 --> 00:00:50,700 If I run this, well, nothing gets printed 17 00:00:50,700 --> 00:00:54,330 because, again, we have to perform some action 18 00:00:54,330 --> 00:00:55,740 on these data types. 19 00:00:55,740 --> 00:00:58,890 And one action that we've learned so far 20 00:00:58,890 --> 00:01:00,963 is this idea of printing. 21 00:01:02,910 --> 00:01:04,739 And we print something 22 00:01:04,739 --> 00:01:09,063 by calling the print keyword with the brackets. 23 00:01:09,990 --> 00:01:12,097 So the brackets is almost like saying, 24 00:01:12,097 --> 00:01:16,257 "Hey, perform this action on these data types." 25 00:01:17,520 --> 00:01:19,023 And if we run this, 26 00:01:20,790 --> 00:01:23,610 we get six right here. 27 00:01:23,610 --> 00:01:25,050 Awesome. 28 00:01:25,050 --> 00:01:27,570 So, not only are we using print, 29 00:01:27,570 --> 00:01:30,780 but we're also using the plus sign to perform an action, 30 00:01:30,780 --> 00:01:33,123 to add the two data types together. 31 00:01:34,020 --> 00:01:35,670 And as you can imagine, 32 00:01:35,670 --> 00:01:40,140 we can do most mathematical operations, the basic ones. 33 00:01:40,140 --> 00:01:42,360 We can do negative. 34 00:01:42,360 --> 00:01:46,263 We can do, let's say 2 times 4, 35 00:01:48,060 --> 00:01:50,973 and then we can also do 2 divided by 4. 36 00:01:51,900 --> 00:01:53,373 And if click run here, 37 00:01:54,600 --> 00:01:57,360 all right, it looks like everything is working. 38 00:01:57,360 --> 00:02:01,290 We've added, we've subtracted, we've multiplied, 39 00:02:01,290 --> 00:02:03,183 and then we've also divided. 40 00:02:04,620 --> 00:02:06,453 Now, here's the interesting part. 41 00:02:07,650 --> 00:02:10,923 Up until now, we've used what we call integers. 42 00:02:11,760 --> 00:02:14,940 That is, these are whole numbers. 43 00:02:14,940 --> 00:02:19,053 There's no decimal places, they're just, well, integers. 44 00:02:20,280 --> 00:02:24,513 And a neat trick that I can do here is I can actually say, 45 00:02:25,387 --> 00:02:30,387 "Hey, what's the type of 2 plus 4?" 46 00:02:32,970 --> 00:02:34,473 If I click run here, 47 00:02:35,610 --> 00:02:38,073 all right, let's decipher what just happened. 48 00:02:39,600 --> 00:02:42,000 I've taught you another action that we can perform 49 00:02:42,000 --> 00:02:43,830 which is something called type 50 00:02:43,830 --> 00:02:47,577 which tells us, "Hey, what data type is this?" 51 00:02:48,660 --> 00:02:52,290 And just like in math, we go bracket by bracket. 52 00:02:52,290 --> 00:02:55,387 So the first part, Python says, 53 00:02:55,387 --> 00:02:57,150 "Hey, what's 2 plus 4? 54 00:02:57,150 --> 00:02:59,457 Well, that's going to be six." 55 00:03:00,330 --> 00:03:01,267 And it's going to say, 56 00:03:01,267 --> 00:03:04,560 "Hey, what's the type of six?" 57 00:03:04,560 --> 00:03:07,020 Well, the type of six, that's an integer. 58 00:03:07,020 --> 00:03:10,410 So it's going to say class int. 59 00:03:10,410 --> 00:03:13,140 We don't have to worry about the class keyword for now. 60 00:03:13,140 --> 00:03:15,000 That's something that we'll talk about later. 61 00:03:15,000 --> 00:03:18,510 But we see here that we're using int for integer. 62 00:03:18,510 --> 00:03:22,890 And then finally, after this gets evaluated by Python, 63 00:03:22,890 --> 00:03:26,643 we print out whatever this does, which is class in. 64 00:03:28,560 --> 00:03:29,850 Now, check this out. 65 00:03:29,850 --> 00:03:32,643 Let's do the same for all these ones as well. 66 00:03:33,780 --> 00:03:37,980 So we're gonna say, type here, type here, 67 00:03:40,380 --> 00:03:44,070 and then type here. 68 00:03:44,070 --> 00:03:46,530 And if this syntax is intimidating, don't worry. 69 00:03:46,530 --> 00:03:48,090 This is something that you get used to. 70 00:03:48,090 --> 00:03:50,220 If this is your first programming language, 71 00:03:50,220 --> 00:03:54,030 it is not going to be easy because well, if it was easy 72 00:03:54,030 --> 00:03:55,650 then everybody would be doing it. 73 00:03:55,650 --> 00:03:56,940 So hang in there. 74 00:03:56,940 --> 00:03:59,070 Trust me, as you practice more 75 00:03:59,070 --> 00:04:02,280 this is going to start making more and more sense. 76 00:04:02,280 --> 00:04:04,200 Now, before I click run, 77 00:04:04,200 --> 00:04:08,043 what do you think the output of each one of these lines are? 78 00:04:09,810 --> 00:04:12,423 Ready? Give it a guess and let's click run. 79 00:04:15,450 --> 00:04:17,793 All right, we got int. 80 00:04:18,870 --> 00:04:21,510 For six, we have negative two here, 81 00:04:21,510 --> 00:04:23,400 which is also an integer. 82 00:04:23,400 --> 00:04:28,140 We have eight here, which again, is also an integer. 83 00:04:28,140 --> 00:04:29,913 But then we have float. 84 00:04:31,680 --> 00:04:35,430 Because two divided by four is 0.5. 85 00:04:35,430 --> 00:04:37,740 Hmm, what is that? 86 00:04:37,740 --> 00:04:41,370 Well, remember we are talking about two data types here. 87 00:04:41,370 --> 00:04:45,180 We're talking about int and float. 88 00:04:45,180 --> 00:04:49,440 And float is what we call a floating point number. 89 00:04:49,440 --> 00:04:53,070 A floating point number is simply a number 90 00:04:53,070 --> 00:04:54,810 with a decimal point. 91 00:04:54,810 --> 00:04:59,810 In our case, this is 0.5, so it's a floating point number. 92 00:05:02,310 --> 00:05:04,413 So if we write a number, 93 00:05:05,250 --> 00:05:08,250 let's say we'll do print, type, 94 00:05:08,250 --> 00:05:11,703 and then I'll say 0.00001. 95 00:05:12,810 --> 00:05:14,070 What do you think we'll get? 96 00:05:14,070 --> 00:05:17,133 Well, we would get a float. 97 00:05:18,330 --> 00:05:23,193 If I do 5.0001, again, we'll get a float. 98 00:05:24,180 --> 00:05:26,253 What about the number zero? 99 00:05:27,510 --> 00:05:28,413 If I click run, 100 00:05:30,660 --> 00:05:35,163 I get an int because, well, there's no decimal points. 101 00:05:36,480 --> 00:05:40,440 Why do we need to make this distinction in programming 102 00:05:40,440 --> 00:05:42,870 and specifically in Python? 103 00:05:42,870 --> 00:05:44,770 Well, it's because a float 104 00:05:45,660 --> 00:05:48,870 takes up actually a lot more space in memory 105 00:05:48,870 --> 00:05:51,210 than an integer, right? 106 00:05:51,210 --> 00:05:56,210 Because, remember, this number, the number six, 107 00:05:56,370 --> 00:06:01,370 this needs to get stored in memory on our machine. 108 00:06:01,650 --> 00:06:05,580 And remember that machines don't really understand this. 109 00:06:05,580 --> 00:06:08,460 They understand zeros and one. 110 00:06:08,460 --> 00:06:10,020 And they store this number 111 00:06:10,020 --> 00:06:13,950 in something called a binary or binary numbers 112 00:06:13,950 --> 00:06:16,290 which is zeros and ones. 113 00:06:16,290 --> 00:06:19,830 Now, the problem is when you have decimal places 114 00:06:19,830 --> 00:06:24,830 like zero point, or let's do 10.56, 115 00:06:25,500 --> 00:06:27,030 it's hard to represent that 116 00:06:27,030 --> 00:06:31,500 in a binary number, zeros and ones because of this point. 117 00:06:31,500 --> 00:06:36,500 So a floating point number essentially stores these numbers 118 00:06:37,020 --> 00:06:41,863 in two different location, one for the 10 and one for 56. 119 00:06:43,530 --> 00:06:45,420 Now, we don't need to get technical here 120 00:06:45,420 --> 00:06:46,740 but that's the idea. 121 00:06:46,740 --> 00:06:49,290 The idea is that we need more memory 122 00:06:49,290 --> 00:06:51,510 to store a number like this 123 00:06:51,510 --> 00:06:53,493 than a number like this. 124 00:06:54,480 --> 00:06:57,360 Now, the topic of floating point numbers is really, 125 00:06:57,360 --> 00:06:59,610 really interesting, and I'll link to a resource. 126 00:06:59,610 --> 00:07:02,610 But the best way to learn more about floating points, 127 00:07:02,610 --> 00:07:04,530 again, it's not super important 128 00:07:04,530 --> 00:07:06,750 that you know the technical details, 129 00:07:06,750 --> 00:07:11,313 but if you go to floating point number Python. 130 00:07:13,860 --> 00:07:15,120 Again, you wanna make sure 131 00:07:15,120 --> 00:07:18,003 that you go to the documentation for version three. 132 00:07:19,890 --> 00:07:21,030 And you can actually learn 133 00:07:21,030 --> 00:07:23,400 about floating point arithmetic. 134 00:07:23,400 --> 00:07:26,490 And these official documentation by Python 135 00:07:26,490 --> 00:07:28,680 are always a good tool for you to use 136 00:07:28,680 --> 00:07:31,020 whenever you get confused about something 137 00:07:31,020 --> 00:07:33,693 or you wanna get a little bit more extra detail. 138 00:07:35,910 --> 00:07:38,043 But let's get back to the topic at hand. 139 00:07:40,020 --> 00:07:45,020 Both int and float are used for well numbers, right? 140 00:07:45,450 --> 00:07:50,450 And, Python is going to automatically format the type 141 00:07:50,790 --> 00:07:53,940 to whatever well, makes sense. 142 00:07:53,940 --> 00:07:57,180 For example, if in here, 143 00:07:57,180 --> 00:08:02,180 I do 20 plus 1.1, 144 00:08:02,880 --> 00:08:06,090 one is a integer, 145 00:08:06,090 --> 00:08:08,490 the other one is a floating point number. 146 00:08:08,490 --> 00:08:10,173 But when I click run here, 147 00:08:11,100 --> 00:08:15,120 automatically Python is going to convert it to float. 148 00:08:15,120 --> 00:08:17,160 Let's remove these here so that 149 00:08:17,160 --> 00:08:18,660 we don't get confused by them. 150 00:08:19,500 --> 00:08:23,730 So if I run this, we see that this whole expression 151 00:08:23,730 --> 00:08:27,030 is converted into, well, a float. 152 00:08:27,030 --> 00:08:32,030 Now if I do, let's say 9.9 here, 153 00:08:34,049 --> 00:08:37,679 which will equal to 11 and I click run, 154 00:08:37,679 --> 00:08:41,190 these two floats add up to, 155 00:08:41,190 --> 00:08:42,990 while still a floating point number 156 00:08:42,990 --> 00:08:45,910 because if I remove the type from here 157 00:08:46,800 --> 00:08:51,800 and I click run, it gives me the result 11.0. 158 00:08:53,850 --> 00:08:55,923 It keeps the floating point numbers. 159 00:08:56,790 --> 00:08:57,623 All right. 160 00:08:57,623 --> 00:08:58,650 But at the end of the day, 161 00:08:58,650 --> 00:09:01,020 what we care about is that 162 00:09:01,020 --> 00:09:03,300 Python works the way we expect it to. 163 00:09:03,300 --> 00:09:06,870 That is we can do mathematical operations. 164 00:09:06,870 --> 00:09:10,263 As a matter of fact, we can do a few other things as well. 165 00:09:12,180 --> 00:09:17,180 There's also this idea of the double multiply. 166 00:09:19,080 --> 00:09:21,990 So this means to the power of so two 167 00:09:21,990 --> 00:09:26,463 to the power of two, well, that's going to equal four. 168 00:09:27,480 --> 00:09:31,563 Two to the power of three is going to equal eight. 169 00:09:33,600 --> 00:09:37,743 We also have the double divide. 170 00:09:38,670 --> 00:09:42,660 That is we can do two divided by four. 171 00:09:42,660 --> 00:09:45,870 But then we use two slashes here. 172 00:09:45,870 --> 00:09:50,870 If I click run here, I get zero. 173 00:09:52,350 --> 00:09:55,683 This actually returns an integer. 174 00:09:56,520 --> 00:09:58,320 Round it down. 175 00:09:58,320 --> 00:10:03,320 If I do three divided by four, I get zero. 176 00:10:04,170 --> 00:10:09,170 But if I do five divided by four, I get one. 177 00:10:11,130 --> 00:10:14,883 This gets rounded down to a integer. 178 00:10:16,320 --> 00:10:18,420 Finally, the last operator 179 00:10:18,420 --> 00:10:22,080 that we're gonna learn about is called modulo. 180 00:10:22,080 --> 00:10:24,780 And it looks something like this. 181 00:10:24,780 --> 00:10:29,433 If I do five modulo, which is the percent sign. 182 00:10:30,570 --> 00:10:34,650 Divided by four or modulo four, 183 00:10:34,650 --> 00:10:39,003 if I run this, I get one. 184 00:10:40,830 --> 00:10:44,760 Modulo is used to represent 185 00:10:44,760 --> 00:10:46,920 what's the remainder of this division. 186 00:10:46,920 --> 00:10:49,770 So if I divide five by four, 187 00:10:49,770 --> 00:10:52,530 the remainder of this division will be one. 188 00:10:52,530 --> 00:10:53,977 If I do six divided by four with modulo 189 00:10:53,977 --> 00:10:58,977 and I run, I get two. 190 00:10:59,940 --> 00:11:03,060 Two is the remainder of four. 191 00:11:03,060 --> 00:11:05,580 All right, let's take a break and learn a little bit more 192 00:11:05,580 --> 00:11:08,370 about these numbers in the next video. 193 00:11:08,370 --> 00:11:09,203 Bye-bye.