1 00:00:00,000 --> 00:00:02,790 In some situations, you will need to modify the 2 00:00:02,790 --> 00:00:06,180 datatype of a variable. So for example, you want 3 00:00:06,180 --> 00:00:09,360 to change an integer to a float or an integer to a 4 00:00:09,360 --> 00:00:13,260 Boolean, String to float, etc. And we have actually 5 00:00:13,260 --> 00:00:16,650 a good example here to work on. The input function, 6 00:00:16,680 --> 00:00:20,280 as you saw before, always returns a string. Okay, 7 00:00:20,280 --> 00:00:22,920 even if you give a number, so then if you need to 8 00:00:22,920 --> 00:00:25,020 work with the number you got from the input, 9 00:00:25,020 --> 00:00:27,540 you're going to have a problem because well, this 10 00:00:27,540 --> 00:00:31,200 number will actually be a string, not a number. So 11 00:00:31,200 --> 00:00:33,150 you need to change the type for the variable and 12 00:00:33,150 --> 00:00:35,880 this is called cast, okay. You are going to cast 13 00:00:36,120 --> 00:00:39,420 the type. And to cast a variable, it's very easy. 14 00:00:39,450 --> 00:00:41,460 Okay, so let's say we have an example, let's say 15 00:00:41,460 --> 00:00:45,210 you want to cast a string, okay, to so we have the 16 00:00:45,210 --> 00:00:50,070 string here, a is a string. So if I do type a, I 17 00:00:50,070 --> 00:00:54,690 have a string, I want to cast a to an integer. In 18 00:00:54,690 --> 00:00:58,800 this case, I simply do int a, okay, you simply 19 00:00:58,800 --> 00:01:01,680 use the final data type you want. And then in 20 00:01:01,680 --> 00:01:05,160 parentheses, you put the variable or the value you 21 00:01:05,160 --> 00:01:08,640 have no, okay. If I do int a, you can see now I 22 00:01:08,640 --> 00:01:15,300 have 67, without the quotes. And if I do type int, 23 00:01:15,540 --> 00:01:19,950 a, now this is of class int. So this way, you can 24 00:01:19,950 --> 00:01:23,580 change a value here, from whatever data type it is 25 00:01:23,670 --> 00:01:27,810 to the data type int. You can also do the reverse, 26 00:01:27,810 --> 00:01:29,970 if you want, you can cast something into a string. 27 00:01:30,000 --> 00:01:34,170 Let's say I want to cast 34. This is going to give 28 00:01:34,170 --> 00:01:37,890 the string 34. You can cast it to float for 29 00:01:37,890 --> 00:01:43,380 example, float from three is going to give 3.0. You 30 00:01:43,380 --> 00:01:47,580 can do the opposite int let's say 3.0 is going to 31 00:01:47,580 --> 00:01:53,250 be 3 and let's see, for example 3.7. What do 32 00:01:53,250 --> 00:01:56,610 we have here, we have just three okay. This is 33 00:01:56,610 --> 00:01:59,910 important when you cast a float number to an 34 00:01:59,940 --> 00:02:02,670 integer number, the number is going to be 35 00:02:02,670 --> 00:02:06,030 truncated. Okay, so whatever is after the comma is 36 00:02:06,030 --> 00:02:08,580 going to be last. Okay, so that's important to 37 00:02:08,580 --> 00:02:12,450 know. And then so we can also cast a boolean to an 38 00:02:12,480 --> 00:02:16,350 integer, let's see that int True, is going to 39 00:02:16,350 --> 00:02:20,970 give one an int False is going to give zero. 40 00:02:21,540 --> 00:02:24,510 Okay, so actually, if you want to see a Boolean 41 00:02:24,540 --> 00:02:27,450 with numbers, well when you have zero is going to 42 00:02:27,450 --> 00:02:30,630 be False. If you have one is going to be True, but 43 00:02:30,660 --> 00:02:33,360 in fact, if you have any other number is going to 44 00:02:33,360 --> 00:02:37,350 be True. Okay, if you want to do let's say bool, 45 00:02:37,920 --> 00:02:43,290 from 34, is going to be to bool from minus one is 46 00:02:43,290 --> 00:02:46,350 going to be True. The only value which is going to 47 00:02:46,350 --> 00:02:49,770 give False is zero. Alright, and with that, you 48 00:02:49,770 --> 00:02:53,270 can cast any type to any other type.