1 00:00:00,319 --> 00:00:05,739 Let's now take a look at a different form of data types. So far, 2 00:00:06,070 --> 00:00:09,119 we've been working with strings, right? But now 3 00:00:09,250 --> 00:00:11,520 let's take a look at floating points 4 00:00:11,529 --> 00:00:15,789 and integers otherwise simply known as numbers. 5 00:00:15,939 --> 00:00:16,809 All right. So 6 00:00:17,239 --> 00:00:18,739 let's go ahead and remove 7 00:00:18,930 --> 00:00:20,659 this program and 8 00:00:21,520 --> 00:00:25,700 let me first of all, create a variable X equals to four. 9 00:00:26,290 --> 00:00:28,659 OK? And then Y equals, 10 00:00:29,010 --> 00:00:31,940 let's say 6.0. 11 00:00:32,400 --> 00:00:33,020 Now, 12 00:00:33,150 --> 00:00:38,029 the obvious difference between these two is that X doesn't have any decimal points. 13 00:00:38,040 --> 00:00:41,939 Why does Y has the six point? Oh 14 00:00:42,270 --> 00:00:42,700 All right. 15 00:00:42,860 --> 00:00:45,060 In fact, let me make this a bit more reasonable. 16 00:00:45,069 --> 00:00:48,020 Let's make it 6.3 just as an example, right? So 17 00:00:48,380 --> 00:00:53,939 why in this case would be a floating point because it does have a decimal point 18 00:00:54,049 --> 00:00:57,909 while four will be the integer. So 19 00:00:58,319 --> 00:01:01,470 if I went ahead right now and I printed 20 00:01:01,880 --> 00:01:02,990 X 21 00:01:03,479 --> 00:01:04,930 plus 22 00:01:05,059 --> 00:01:06,000 Y 23 00:01:07,500 --> 00:01:13,529 and I run my program, you can see we're gonna get the number 10.3 24 00:01:13,699 --> 00:01:15,209 pretty straightforward, right? 25 00:01:15,550 --> 00:01:16,440 However, 26 00:01:16,629 --> 00:01:21,389 we could do certain things like say, for example, if you wanted to convert 27 00:01:21,800 --> 00:01:23,230 10.3 28 00:01:23,349 --> 00:01:24,819 being a floating 29 00:01:25,120 --> 00:01:27,879 number, if you wanted to convert it to an integer, 30 00:01:28,379 --> 00:01:33,279 we could simply use a new function called the integer function. 31 00:01:33,690 --> 00:01:37,629 So, what I'm gonna do right here is inside of this first bracket. 32 00:01:37,639 --> 00:01:40,260 I'm going to open up another bracket and 33 00:01:40,650 --> 00:01:42,910 add int. 34 00:01:43,750 --> 00:01:45,610 All right. So int, oh, 35 00:01:46,129 --> 00:01:46,709 sorry, 36 00:01:47,949 --> 00:01:49,809 sorry about that. Int 37 00:01:50,379 --> 00:01:50,819 ok. 38 00:01:50,980 --> 00:01:54,800 So int here is a function that stands for integer 39 00:01:54,989 --> 00:01:57,569 and of course, since we've opened the integer function, 40 00:01:57,790 --> 00:02:00,809 we're going to have to close it as well. 41 00:02:01,540 --> 00:02:02,559 So let me add 42 00:02:02,959 --> 00:02:06,199 the closing brackets. And now if I was to run a program, 43 00:02:06,370 --> 00:02:10,320 you can see it has converted 10.3 to 10 44 00:02:10,559 --> 00:02:11,789 because of the 45 00:02:11,910 --> 00:02:12,800 function 46 00:02:13,259 --> 00:02:15,050 int integer. 47 00:02:15,729 --> 00:02:21,059 So this is the first time that we have added a function inside of another function. 48 00:02:21,070 --> 00:02:22,649 First, we have the print function 49 00:02:22,910 --> 00:02:26,929 and then inside of the print function, we have the integer function. So 50 00:02:27,119 --> 00:02:31,000 this is one thing you should be aware of when it comes to Python programming, 51 00:02:31,399 --> 00:02:32,979 you can have 52 00:02:33,350 --> 00:02:36,210 a function inside of another function. 53 00:02:36,479 --> 00:02:40,660 And in fact, you can have 34 functions instead of one another 54 00:02:40,899 --> 00:02:43,910 just as long as the hierarchy is correct. 55 00:02:43,919 --> 00:02:46,740 In this case right now, I cannot have the integer 56 00:02:46,919 --> 00:02:48,449 function coming in first 57 00:02:48,729 --> 00:02:52,139 and then print. In fact, you know what, let's try it. OK? Why not? 58 00:02:52,919 --> 00:02:54,619 I'm gonna go ahead right now. Print 59 00:02:55,029 --> 00:02:55,649 OK? 60 00:02:57,669 --> 00:03:03,169 And then int OK, what's gonna happen? What's gonna happen? I'm gonna click on run 61 00:03:03,860 --> 00:03:04,759 and there you go. 62 00:03:05,149 --> 00:03:10,309 So even though it kind of, well, it didn't really work. 63 00:03:10,320 --> 00:03:15,529 I mean, we did get the X plus Y, we did get the correct answer to be 10.3. 64 00:03:16,000 --> 00:03:22,339 But unfortunately, it didn't convert the results to an actual integer. So 65 00:03:22,509 --> 00:03:25,479 Python basically ignored the very first part which is the 66 00:03:25,490 --> 00:03:27,529 integer function and then just went ahead and said, 67 00:03:27,539 --> 00:03:29,199 OK, print X plus Y. 68 00:03:29,429 --> 00:03:30,899 And then of course, they told us that, hey, 69 00:03:30,910 --> 00:03:33,770 there's some sort of an issue with the syntax. 70 00:03:33,779 --> 00:03:34,190 So 71 00:03:34,509 --> 00:03:36,729 you have to be careful whenever you're trying to 72 00:03:37,220 --> 00:03:40,570 add functions inside of another function, 73 00:03:40,580 --> 00:03:43,960 there needs to be a hierarchy and it needs to be correct. 74 00:03:43,970 --> 00:03:44,250 So 75 00:03:44,610 --> 00:03:46,960 let's reverse that run again 76 00:03:47,089 --> 00:03:47,970 and there you go. 77 00:03:48,190 --> 00:03:48,710 So 78 00:03:48,970 --> 00:03:55,389 likewise, if I wanted to convert the results to a 79 00:03:55,889 --> 00:03:57,800 floating number, 80 00:03:57,960 --> 00:03:59,960 I could do so as well. So 81 00:04:00,110 --> 00:04:01,240 for example, right, 82 00:04:01,979 --> 00:04:05,039 if I change the Y here to let's say five, 83 00:04:05,240 --> 00:04:05,869 right? 84 00:04:06,520 --> 00:04:11,940 But instead of nine, which would be the obvious answer here, I wanted it to be 9.0 85 00:04:12,380 --> 00:04:14,699 I will change the integer function in here 86 00:04:14,960 --> 00:04:16,619 to float. 87 00:04:17,230 --> 00:04:19,048 So this is the opposite, right? So 88 00:04:19,540 --> 00:04:20,940 check this out, I'm going to click on run 89 00:04:21,238 --> 00:04:24,220 and there you go. It is now 9.0. 90 00:04:24,600 --> 00:04:28,950 It's, you know, there's a good chance you may not need to use the integer 91 00:04:29,190 --> 00:04:31,260 or float function in your programs. 92 00:04:31,269 --> 00:04:33,380 It all depends on the kind of programs you will create. 93 00:04:33,670 --> 00:04:36,649 But nevertheless, it's important to understand 94 00:04:36,820 --> 00:04:38,730 these concepts that you can add, 95 00:04:39,059 --> 00:04:42,070 you can convert one data type to another 96 00:04:42,269 --> 00:04:44,670 and then you can also have one function 97 00:04:44,820 --> 00:04:49,329 inside of another. So thank you for watching. I will see you in the next class.