1 00:00:00,000 --> 00:00:03,180 By now, we have only used round numbers in 2 00:00:03,180 --> 00:00:07,680 variables, which we can also call integers. But in 3 00:00:07,680 --> 00:00:10,170 fact, there are more types you can use to 4 00:00:10,170 --> 00:00:13,380 represent different kinds of data. And let's 5 00:00:13,410 --> 00:00:16,350 discover them now. And first, I'm going to give 6 00:00:16,350 --> 00:00:19,830 you another useful Python function, which is named 7 00:00:19,950 --> 00:00:25,020 type. Okay. So in Python, you have some built in 8 00:00:25,050 --> 00:00:28,020 functions you can use, okay, and to call a 9 00:00:28,020 --> 00:00:31,320 function, it's simple. You just write the name of 10 00:00:31,350 --> 00:00:34,530 the function, and then open and close parentheses 11 00:00:34,560 --> 00:00:37,410 and in the parentheses, you're going to give any 12 00:00:37,410 --> 00:00:39,990 parameter you need to give. Sometimes there is no 13 00:00:39,990 --> 00:00:42,780 parameter, sometimes you have to give parameters. 14 00:00:42,780 --> 00:00:46,410 So here, let's say I give type 3. So I simply 15 00:00:46,410 --> 00:00:49,920 put a round number here, inside the type function, 16 00:00:49,950 --> 00:00:54,180 and this gives us class int. So don't worry about 17 00:00:54,180 --> 00:00:57,420 the class for now. Okay, just focus here on the int. So 18 00:00:57,480 --> 00:01:01,950 int for integer, so I have my variable a, which is 19 00:01:01,950 --> 00:01:07,050 equal to five. If I do type a, okay, I can also 20 00:01:07,050 --> 00:01:09,810 get type of a variable directly, and you can see 21 00:01:09,840 --> 00:01:14,910 type integer. So this is the first type, okay, you 22 00:01:14,910 --> 00:01:18,390 have used and one of the most important. Now let's 23 00:01:18,390 --> 00:01:24,000 say, type(4.5). This is, as you can see, now it's 24 00:01:24,000 --> 00:01:27,930 not int anymore, it is float. So this is a float 25 00:01:27,960 --> 00:01:35,130 number. If I do type(3.0), we also get float. Okay, 26 00:01:35,130 --> 00:01:37,980 you can see as soon as I add a point to the 27 00:01:37,980 --> 00:01:41,190 number, even if after this is zero, we get the 28 00:01:41,190 --> 00:01:44,340 float number. So this is a different datatype 29 00:01:44,340 --> 00:01:49,140 okay, int and float. And so if I do, let's say e 30 00:01:49,380 --> 00:01:56,280 is equal to 4.6, and then I do type(e), I get class 31 00:01:56,370 --> 00:02:00,270 float. So at anytime, you can just use type with 32 00:02:00,300 --> 00:02:02,850 the name of the variable to see what kind of data 33 00:02:02,850 --> 00:02:06,150 type you have here. Okay, now let's see, let's say 34 00:02:06,150 --> 00:02:12,570 do type(4+6). Okay, you can see so 4 35 00:02:12,570 --> 00:02:15,990 + 6 will be evaluated to 10. And then 10 will 36 00:02:15,990 --> 00:02:20,070 be passed to the type function, and this is going 37 00:02:20,070 --> 00:02:26,653 to give us int. Now if I do type, let's say (4.5+4.3), 38 00:02:26,653 --> 00:02:29,850 okay, you can see the result is float. 39 00:02:29,910 --> 00:02:36,420 And if I do type(4.5+3), so here I am 40 00:02:36,480 --> 00:02:40,260 adding a float number and an int number, and the 41 00:02:40,260 --> 00:02:43,350 result will be float. So you can see whenever you 42 00:02:43,350 --> 00:02:46,530 use a float number in an operation, when the 43 00:02:46,530 --> 00:02:49,890 result is going to be float. So great. We have two 44 00:02:49,890 --> 00:02:54,030 main datatype for numbers, integers and float 45 00:02:54,060 --> 00:02:57,720 numbers. Now we're going to see two new other data 46 00:02:57,720 --> 00:03:00,660 types, which are representing other things than 47 00:03:00,660 --> 00:03:04,770 numbered. The first one is a Boolean. So if I 48 00:03:04,770 --> 00:03:08,640 write True, okay, if I write False like this, so 49 00:03:08,640 --> 00:03:11,400 True with uppercase and False also with 50 00:03:11,430 --> 00:03:13,680 uppercase, you can see it's working, this is 51 00:03:13,680 --> 00:03:16,860 working nicely, because those are values you can 52 00:03:16,860 --> 00:03:20,010 use, okay? Those are Boolean values. So a Boolean 53 00:03:20,010 --> 00:03:23,370 is simply a data type, which only has two values, 54 00:03:23,550 --> 00:03:26,700 True or False. And we are going to come back to 55 00:03:26,700 --> 00:03:30,210 this actually, later when we work on conditions. 56 00:03:30,210 --> 00:03:32,970 So that will be very useful to create conditions. 57 00:03:33,360 --> 00:03:34,725 So if I do type 58 00:03:35,669 --> 00:03:40,409 (True), you can see class bool for Boolean, can also 59 00:03:40,409 --> 00:03:45,239 type(False) Boolean. Okay, and then the fourth type 60 00:03:45,239 --> 00:03:48,569 we're going to see here is the string datatype. So 61 00:03:48,569 --> 00:03:53,489 if I do type("hello"), like this, you can see class, 62 00:03:53,849 --> 00:03:58,139 str, str for string. And one thing about strings 63 00:03:58,139 --> 00:04:01,409 is that you can use if you want double quotes or 64 00:04:01,469 --> 00:04:04,469 single quotes, okay, you can see this is also 65 00:04:04,469 --> 00:04:07,529 going to give us string. So for now, the 66 00:04:07,529 --> 00:04:10,739 difference is not that important. I'm just going 67 00:04:10,739 --> 00:04:14,789 to follow and continue to close with double quotes 68 00:04:14,819 --> 00:04:17,399 like this. But the important thing is that you 69 00:04:17,399 --> 00:04:20,488 stay consistent. So if you use double quotes, you 70 00:04:20,488 --> 00:04:23,159 use double quotes at the end. If you use single 71 00:04:23,159 --> 00:04:25,799 quotes, you use a single quote at the end, okay, 72 00:04:25,799 --> 00:04:28,889 if I try to do let's say "hello', like this, I open 73 00:04:28,889 --> 00:04:32,159 with a double quote, I close with a single quote, 74 00:04:32,609 --> 00:04:36,209 I'm going to have a SyntaxError, okay? This is 75 00:04:36,209 --> 00:04:40,559 not going to work. So if I just create a text 76 00:04:40,589 --> 00:04:44,009 variable, which contains "Hello", for example, and 77 00:04:44,009 --> 00:04:49,769 then I do type(text), I get class str, and one thing 78 00:04:49,769 --> 00:04:52,769 that is important is whenever you add quotes to 79 00:04:52,799 --> 00:04:55,079 actually anything, this is going to become a 80 00:04:55,079 --> 00:04:59,099 string. Okay. If I add quote to three, this is 81 00:04:59,099 --> 00:05:02,819 a string Okay. This is not an int number. Okay, 82 00:05:02,819 --> 00:05:05,279 very important to make difference, okay, you can 83 00:05:05,279 --> 00:05:07,709 have three, but this can be a string because you 84 00:05:07,709 --> 00:05:13,619 have put quotes. Same for, let's say 3.0, which 85 00:05:13,649 --> 00:05:16,859 3.0 is a float number, but this is a string, and 86 00:05:16,859 --> 00:05:22,259 also type, if I do True like this, this is also a 87 00:05:22,259 --> 00:05:25,349 string. Okay, and one thing you can do also with 88 00:05:25,379 --> 00:05:28,589 strings, these, you can use the plus operator. 89 00:05:28,589 --> 00:05:33,329 So if I do hello, like this plus, let's say, 90 00:05:33,569 --> 00:05:37,079 world. So I have added the space here. Okay, I 91 00:05:37,079 --> 00:05:39,479 press Enter, and you can see the result is hello 92 00:05:39,479 --> 00:05:43,079 world. So this is a specificity of strings. 93 00:05:43,079 --> 00:05:45,299 Because of course, for a string, it doesn't make 94 00:05:45,299 --> 00:05:49,199 any sense to kind of multiply two strings, okay. 95 00:05:49,559 --> 00:05:53,339 But you can use the plus sign to just concatenate 96 00:05:53,519 --> 00:05:56,609 two different strings and make it just one string, 97 00:05:56,609 --> 00:05:59,429 and the result will be a string. Okay, so if you 98 00:05:59,429 --> 00:06:03,479 try to do type on this, you will get also str. And 99 00:06:03,479 --> 00:06:05,849 this, of course, you can store it inside a 100 00:06:05,849 --> 00:06:08,279 variable. You could create one variable for this 101 00:06:08,369 --> 00:06:10,949 one variable for this and create a new variable, 102 00:06:11,069 --> 00:06:14,159 where you just add the two variables, and you will 103 00:06:14,159 --> 00:06:16,949 get the same result. So great, you have just 104 00:06:16,949 --> 00:06:19,919 discovered four Python data types, you're going to 105 00:06:19,919 --> 00:06:24,719 use in all your future programs, integer, float, 106 00:06:24,869 --> 00:06:28,439 Boolean, and string. One thing to note here, you 107 00:06:28,439 --> 00:06:31,139 don't need to manually precise the datatype. When 108 00:06:31,139 --> 00:06:34,019 you create a variable, the data type will be 109 00:06:34,049 --> 00:06:37,619 automatically evaluated, depending on the value 110 00:06:37,649 --> 00:06:42,119 you're assigned to the variable. And one other super 111 00:06:42,149 --> 00:06:45,599 important thing, try not to change a variable 112 00:06:45,599 --> 00:06:48,719 datatype after you have created it. So for 113 00:06:48,719 --> 00:06:51,719 example, let's say I have name, which is equal to 114 00:06:52,589 --> 00:06:58,019 Ed. Okay, name contains Ed and I can type name, 115 00:06:58,289 --> 00:07:02,129 okay, this is an str. Now, what I can also do, and 116 00:07:02,129 --> 00:07:04,589 this is valid in Python, I can just do name is 117 00:07:04,589 --> 00:07:09,509 equal to two. So no name is to any file type name, 118 00:07:09,809 --> 00:07:13,679 I got class ints. So the name was before when I 119 00:07:13,679 --> 00:07:15,719 created name for the first time it was a string 120 00:07:15,899 --> 00:07:19,859 and now it is an integer. This is a very bad practice, 121 00:07:19,889 --> 00:07:23,219 don't do that. Okay, you won't get a Python error 122 00:07:23,219 --> 00:07:26,609 when you just assign a new value with a new type 123 00:07:26,639 --> 00:07:30,329 to the variable. But this is a sure way to mess 124 00:07:30,329 --> 00:07:34,169 up with your program and get a lot of errors later 125 00:07:34,169 --> 00:07:37,409 on. So once you've created the variable stick to 126 00:07:37,409 --> 00:07:40,919 the same data type for this variable. And because I 127 00:07:40,919 --> 00:07:43,469 have also previously told you to use meaningful 128 00:07:43,469 --> 00:07:46,229 names, so let's use a few examples. For example, 129 00:07:46,229 --> 00:07:50,789 you have the user_age, okay, 45 or 55. You have 130 00:07:50,819 --> 00:07:53,519 you can use the user_name for example, let's say, 131 00:07:54,119 --> 00:07:58,169 Bob, okay. And then if you want to float number, 132 00:07:58,169 --> 00:08:03,569 let's say room_temperature, which is equal to 133 00:08:03,569 --> 00:08:11,339 34.5. And let's say is_activated which is equal to 134 00:08:11,789 --> 00:08:14,699 False. Okay, so here you have an example with four 135 00:08:14,729 --> 00:08:17,609 different variables with four different data types 136 00:08:17,639 --> 00:08:20,608 and with meaningful names.