1 00:00:00,000 --> 00:00:02,200 [no audio] 2 00:00:02,210 --> 00:00:05,210 Friends, in this video we are going to discuss about data types of 3 00:00:05,700 --> 00:00:10,300 your Python or variable data types in your Python. 4 00:00:11,300 --> 00:00:16,200 See before going to start about this concept, you know already 5 00:00:16,200 --> 00:00:17,600 variable, right? 6 00:00:17,600 --> 00:00:21,300 Simply you are taking some 'x = 2', any number, and you 7 00:00:21,300 --> 00:00:24,300 are saying that this is a variable. I can also take some other 8 00:00:24,300 --> 00:00:29,900 variable like 'y =' some 4.8 right, or let's say some 9 00:00:29,900 --> 00:00:34,100 'z=' some '3 +' some '4j', but instead of 'j' 10 00:00:34,100 --> 00:00:38,100 I have taken 'i'. I mean we have three variables, 11 00:00:39,500 --> 00:00:43,900 right, and in first variable I have, any way in all these 12 00:00:43,900 --> 00:00:48,200 three variables you have number only, but strictly speaking 'x' is an integer, 13 00:00:48,300 --> 00:00:53,300 'y' is some float 'z' is complex. That means based on 14 00:00:53,300 --> 00:00:57,400 which type of data you are storing into your variable, based on that 15 00:00:57,400 --> 00:01:02,000 we have data types or variable data types. And one more thing 16 00:01:02,000 --> 00:01:05,000 guys, you know whenever if you assign something like any 17 00:01:05,000 --> 00:01:08,000 variable equal to any value, right, 18 00:01:08,700 --> 00:01:13,400 so Python is going to take some RAM memory and in that you're 19 00:01:13,400 --> 00:01:16,800 storing a value called '4', and whatever the address is there 20 00:01:16,800 --> 00:01:19,300 for this memory that is represented with 'x'. 21 00:01:20,300 --> 00:01:23,800 Now, if you want to take, the value of 'x' directly simply you are taking 22 00:01:23,800 --> 00:01:26,600 'x', but if you want to find what is the address of your 23 00:01:26,600 --> 00:01:29,700 'x', so for that there is a small syntax. 24 00:01:29,700 --> 00:01:30,700 Let me open that. 25 00:01:30,800 --> 00:01:31,900 Let me show you that. 26 00:01:33,600 --> 00:01:34,800 Let me enter into my Python. 27 00:01:34,800 --> 00:01:36,500 You can use this from anywhere, 28 00:01:36,900 --> 00:01:42,600 I mean from both Python Script or Program or Panel of your 29 00:01:42,600 --> 00:01:46,800 Python. 'id(x)', will give the memory location of your variable, 30 00:01:47,100 --> 00:01:49,700 okay. Guys, this point is very, very important for your online 31 00:01:49,700 --> 00:01:53,700 exams. Just make a note. 'id(x)' will give your 32 00:01:53,700 --> 00:01:55,700 variable memory location. 33 00:01:56,400 --> 00:01:58,500 But if you want to get variable value directly you have to take 34 00:01:58,500 --> 00:02:00,000 variable itself, right? 35 00:02:00,200 --> 00:02:05,600 See, sorry. 'x = 5', I can directly take 'print(x)', 36 00:02:05,600 --> 00:02:10,199 I can get value of 'x'. But if I want to get the 'id', memory 37 00:02:10,199 --> 00:02:12,400 location of your 'x' I have to take in this way. 38 00:02:13,600 --> 00:02:16,500 So otherwise I can store 'id(x)', or address of 39 00:02:16,500 --> 00:02:17,800 'x' '=id(x)'. 40 00:02:19,100 --> 00:02:22,800 I mean I am defining one new variable called 'id_x', and into 41 00:02:22,800 --> 00:02:26,100 that I assign 'id(x)'. I can do it in this way also. 42 00:02:27,300 --> 00:02:28,300 Okay, that's fine. 43 00:02:28,400 --> 00:02:32,200 Now let's come back to your discussion, data types, right? 44 00:02:33,300 --> 00:02:36,600 First thing guys, every value in Python has a data type. 45 00:02:36,700 --> 00:02:41,200 It may be integer, or float, or complex, or some string, or some 46 00:02:41,200 --> 00:02:42,400 Boolean, right? 47 00:02:42,400 --> 00:02:46,900 We have different data types in your Python, right. And guys, 48 00:02:46,900 --> 00:02:49,900 whatever the point we have here, right that may or may not 49 00:02:49,900 --> 00:02:53,500 be understood by you as of now because if you are familiar 50 00:02:53,500 --> 00:02:56,100 with some OOPS concepts of any other programming language 51 00:02:56,100 --> 00:02:58,200 then you can easily understand the second point. 52 00:02:58,300 --> 00:03:00,600 If you don't know just forget about second point, we will 53 00:03:00,600 --> 00:03:03,400 discuss it while working with OOPS in your Python. 54 00:03:04,900 --> 00:03:08,000 So that is, "Since everything is an object in Python, 55 00:03:08,100 --> 00:03:11,300 so whatever you are creating, whatever you are writing no, 56 00:03:11,300 --> 00:03:15,100 that is like an object in your Python Programming. So data 57 00:03:15,100 --> 00:03:19,300 types are actually classes and variables, right. 58 00:03:19,500 --> 00:03:22,700 Your data types are actually have classes and variables, 59 00:03:23,000 --> 00:03:25,400 and they are like instances of the classes. 60 00:03:25,400 --> 00:03:27,200 [no audio] 61 00:03:27,200 --> 00:03:28,200 That's fine. 62 00:03:29,100 --> 00:03:32,700 So based on which type of data you are storing into your 63 00:03:32,700 --> 00:03:34,100 variable, based on that 64 00:03:34,100 --> 00:03:38,400 we have different types of data types, right. Then we have 65 00:03:38,900 --> 00:03:41,900 various, but I'm going with as of now basic data types. 66 00:03:42,000 --> 00:03:44,600 They are like numbers. In numbers 67 00:03:44,600 --> 00:03:50,200 you have integer data, float, and complex; strings; Boolean, 68 00:03:51,000 --> 00:03:55,200 okay. Let me open a script and there I will write. 69 00:03:56,900 --> 00:03:58,700 So I opened my Sublime Text. 70 00:03:58,900 --> 00:04:04,900 Let me give a name for my Python Script, right. Just click 71 00:04:04,900 --> 00:04:09,900 on 'Ctrl + S', just press 'Ctrl + S', so we are working with 72 00:04:09,900 --> 00:04:13,700 our, let me take 'Desktop', there 73 00:04:13,700 --> 00:04:16,100 we have one folder called 'PythonScripts'. 74 00:04:16,100 --> 00:04:17,500 Let me create here, 75 00:04:17,500 --> 00:04:20,300 [no audio] 76 00:04:20,300 --> 00:04:27,899 'working_with_data_types.py', right. Fine. 77 00:04:28,800 --> 00:04:32,000 So guys, first thing I am writing 'x=' some number 3, 78 00:04:32,700 --> 00:04:37,000 okay, 'y=' some number 4.6, and 'z=' some number 79 00:04:38,100 --> 00:04:42,700 '3+4i', right? 80 00:04:42,700 --> 00:04:45,100 [no audio] 81 00:04:45,100 --> 00:04:49,700 Then let me print first your variable 'x', and then let me print 82 00:04:49,700 --> 00:04:55,800 your variable 'y', and let me print your variable 'z', right. Save 83 00:04:55,800 --> 00:04:58,600 it and run it. So to run just to press 'Ctrl + B'. 84 00:04:59,100 --> 00:05:01,000 So you're getting your all datas, right. 85 00:05:02,100 --> 00:05:04,600 So guys, if you observe here I defined my variables, 86 00:05:04,600 --> 00:05:06,000 three variables in three lines. 87 00:05:06,000 --> 00:05:09,500 Of course, I can also do define in this way. In a single line 88 00:05:09,500 --> 00:05:12,900 if you want to define multiple variables you can also go in this way. 89 00:05:13,400 --> 00:05:14,500 This is also valid one. 90 00:05:14,600 --> 00:05:16,600 Just observe the output, you're getting same output, right? 91 00:05:18,500 --> 00:05:23,700 Fine. Now, and even if you want to display your all variables 92 00:05:23,700 --> 00:05:26,800 with one single 'print' statement simply you can write 93 00:05:26,800 --> 00:05:29,500 'x, y, z'. 94 00:05:30,100 --> 00:05:31,300 This is also valid one, 95 00:05:32,100 --> 00:05:35,700 okay. Now, let me run this and see the output. 96 00:05:35,700 --> 00:05:37,600 [no audio] 97 00:05:37,600 --> 00:05:38,900 You are getting same output, 98 00:05:40,000 --> 00:05:43,000 right, but in a single line you are getting. So how to print in multiple lines, 99 00:05:43,000 --> 00:05:44,000 we will see it. 100 00:05:44,800 --> 00:05:46,600 Right. Okay, fine. 101 00:05:46,800 --> 00:05:53,800 So just for clarity, just I am maintaining 'x=', and 102 00:05:53,800 --> 00:05:58,100 'y=' and 'z=', and then I am printing separately, 'print(x)', 103 00:05:58,100 --> 00:06:00,000 [no audio] 104 00:06:00,000 --> 00:06:01,100 then 'print(y)', 105 00:06:01,100 --> 00:06:06,100 [no audio] 106 00:06:06,100 --> 00:06:07,100 'print(z)'. 107 00:06:07,100 --> 00:06:09,100 [no audio] 108 00:06:09,100 --> 00:06:11,800 Fine. At the same time now 109 00:06:11,800 --> 00:06:17,000 what I am doing is I am also printing 'x, type(x)'. So 110 00:06:17,000 --> 00:06:21,400 I can print with the 'type(x)', right and see the output of 111 00:06:21,400 --> 00:06:28,500 your 'x' value, 'x' type. Same way 'y, type(y)', and then 112 00:06:28,600 --> 00:06:30,500 already we know this what is the type, right? 113 00:06:30,500 --> 00:06:33,500 [no audio] 114 00:06:33,500 --> 00:06:35,900 Observe the output you're getting - integer, float, and complex. 115 00:06:36,400 --> 00:06:39,000 So anyway, first of all these three variables are number data 116 00:06:39,000 --> 00:06:43,500 types, specifically 'x' is integer, 'y' is float, and 'z' is complex. 117 00:06:44,000 --> 00:06:45,900 So this is one data type, suppose. 118 00:06:47,200 --> 00:06:52,600 Right. Now, let me comment this. You have second data type as strings, 119 00:06:53,500 --> 00:06:57,800 string. String is nothing but group of characters, maybe single 120 00:06:57,800 --> 00:07:02,100 character also. Let's say I am taking a variable name, 121 00:07:02,400 --> 00:07:04,400 that is 'my_name' or 122 00:07:04,400 --> 00:07:06,400 [no audio] 123 00:07:06,400 --> 00:07:07,400 'lan_name', 124 00:07:08,300 --> 00:07:10,000 right. You can take any variable. 125 00:07:10,000 --> 00:07:13,500 Simply you can take 'l=' also. Just suitable variable 126 00:07:13,500 --> 00:07:18,400 name, I am selecting 'lan_name="python scripting"'. 127 00:07:19,600 --> 00:07:22,100 So guys, if you observe whatever you are writing on right 128 00:07:22,100 --> 00:07:25,600 side of your equal symbol, that is a string. If it is a string 129 00:07:25,600 --> 00:07:29,000 you have to mention that string inside of quotations, 130 00:07:29,900 --> 00:07:33,000 same as your 'print'. Through 'print' you are printing some string 131 00:07:33,000 --> 00:07:36,000 no? If it is a string you have to write inside of your quotations, 132 00:07:36,400 --> 00:07:39,400 and that quotations maybe single quotation or double quotation. 133 00:07:39,400 --> 00:07:41,300 Let me first work with single quotation 134 00:07:42,700 --> 00:07:43,600 and see the output, 135 00:07:44,800 --> 00:07:48,100 or I can also define like, you know single quotations as well. 136 00:07:48,100 --> 00:07:50,400 [no audio] 137 00:07:50,400 --> 00:07:51,400 That's it. 138 00:07:51,400 --> 00:07:53,600 [no audio] 139 00:07:53,600 --> 00:07:56,000 Right. And let me do one thing. 140 00:07:56,000 --> 00:07:58,200 [no audio] 141 00:07:58,200 --> 00:08:00,000 I am taking 'my_name= 142 00:08:01,800 --> 00:08:05,000 narendra'. So 'print(my_name)'. 143 00:08:05,000 --> 00:08:07,600 [no audio] 144 00:08:07,600 --> 00:08:12,400 Right. So if you observe 12th line you are defining a string. If 145 00:08:12,400 --> 00:08:15,200 it is a string actually you have to write inside of quotations. 146 00:08:15,200 --> 00:08:18,300 It may be single or double or even maybe triple quotes also. 147 00:08:19,200 --> 00:08:21,400 But as of now I am going to work with single and double. 148 00:08:22,100 --> 00:08:25,600 For time being just remember only these two way of defining 149 00:08:25,600 --> 00:08:28,500 your strings, we'll discuss the triple quotes somewhere else. 150 00:08:30,000 --> 00:08:33,700 Fine. Now if you observe 'my_name=', string I am 151 00:08:33,700 --> 00:08:36,500 writing but this string I'm not writing in quotation. 152 00:08:36,500 --> 00:08:40,600 And if you run this, see the output what you are getting. You 153 00:08:40,600 --> 00:08:43,400 are getting an error called "name 'narendra' is not defined". 154 00:08:44,200 --> 00:08:46,299 In case if it is already a variable 155 00:08:46,799 --> 00:08:48,900 then this value will be assigned to this 156 00:08:48,900 --> 00:08:52,200 like, let me explain with example. Suppose 'x=2' 157 00:08:52,200 --> 00:08:57,600 I have, and 'y=x' if I write. 'x' is already defined. 'x' 158 00:08:57,600 --> 00:09:00,300 value is there too. Now that value you are assigning to 'y', 159 00:09:00,300 --> 00:09:01,700 and in this case, this is correct. 160 00:09:02,600 --> 00:09:06,100 But in our program nowhere we are defining variable called 161 00:09:06,100 --> 00:09:08,600 'narendra', that's why it is giving, "name 162 00:09:08,900 --> 00:09:11,900 'narendra' is not defined", but actually our intention is 163 00:09:11,900 --> 00:09:14,200 'narendra' is not a variable, right? 164 00:09:14,600 --> 00:09:15,800 'narendra' is a data. 165 00:09:15,900 --> 00:09:18,600 That's why you have to write inside of your quotations. 166 00:09:18,600 --> 00:09:21,600 Now, it will work perfectly. That's it. 167 00:09:23,000 --> 00:09:26,200 Right. And if you want to know the type of your variable 168 00:09:26,300 --> 00:09:30,800 always you can 'print(type())', your variable name so that you 169 00:09:30,800 --> 00:09:34,500 will get your variable type, which type of data you stored 170 00:09:34,500 --> 00:09:36,200 into your variable, that is a string. 171 00:09:36,200 --> 00:09:39,600 [no audio] 172 00:09:39,600 --> 00:09:41,600 Right. Then, 173 00:09:42,600 --> 00:09:45,500 the next one is you have Boolean data types. 174 00:09:46,300 --> 00:09:48,200 So guys in your strings you know, let me take simply 175 00:09:48,200 --> 00:09:51,000 'my_name=' some "x" also. Now here 176 00:09:52,100 --> 00:09:56,200 I am redeclaring my variable name as 'x'. Now 177 00:09:56,200 --> 00:09:59,900 see the output, final output. "x", you are getting. I mean, 178 00:09:59,900 --> 00:10:04,300 you can also take single character as your string, no problem. 179 00:10:05,100 --> 00:10:08,900 See the output. You're getting class as 'str'. "x" is also a string. 180 00:10:08,900 --> 00:10:11,000 [no audio] 181 00:10:11,000 --> 00:10:13,900 Okay, this is fine. Now, let me comment multiple lines. 182 00:10:14,400 --> 00:10:17,000 I'm commenting. So you know, what is the purpose of comment, 183 00:10:17,000 --> 00:10:20,800 I mean triple quotes? To comment multiple lines, right? Now 184 00:10:20,800 --> 00:10:24,400 if I run this program, no output because all lines are commented. 185 00:10:26,100 --> 00:10:29,200 Fine. Now observe that 186 00:10:29,200 --> 00:10:31,600 [no audio] 187 00:10:31,600 --> 00:10:37,000 I am going to take something called 'my_value=True'. 188 00:10:38,400 --> 00:10:42,400 Right. So guys, you know 'True' is not a variable here. 189 00:10:44,100 --> 00:10:46,100 And suppose if you feel 'True' is a string you should 190 00:10:46,100 --> 00:10:50,300 write in quotations, and in case if 'True' is not present 191 00:10:50,300 --> 00:10:51,500 then what will happen? 192 00:10:52,400 --> 00:10:55,600 You will get an error. If 'True' is not a variable you will 193 00:10:55,600 --> 00:11:00,200 get an error but except 'True' and 'False'. 194 00:11:00,300 --> 00:11:01,800 Let me take 'my_new_value 195 00:11:03,300 --> 00:11:04,400 =False'. 196 00:11:05,900 --> 00:11:07,300 Let me run this and see the output. 197 00:11:07,300 --> 00:11:09,000 You're not getting any output, at the same time 198 00:11:09,000 --> 00:11:10,800 you're not getting any error as well. 199 00:11:12,000 --> 00:11:14,500 But if I take 'my_one_more_value 200 00:11:16,300 --> 00:11:20,600 =true', and if I run that, see the output 201 00:11:20,600 --> 00:11:23,900 what you are getting. 'true' is not defined. Small letter 202 00:11:23,900 --> 00:11:26,500 't', 'true' is not defined. Same way 'T' 203 00:11:26,500 --> 00:11:29,500 also not defined, right but you are not getting error here, 204 00:11:29,700 --> 00:11:32,900 but you are getting error while defining in this way. 205 00:11:33,200 --> 00:11:38,200 That means actually only 'True', and only 'False', 206 00:11:39,200 --> 00:11:42,700 these two are for your Boolean, right. 207 00:11:42,700 --> 00:11:49,900 Let me print your 'my_name', sorry 'my_value', and then 'type()' 208 00:11:49,900 --> 00:11:51,300 your 'my_value'. 209 00:11:51,300 --> 00:11:53,800 [no audio] 210 00:11:53,800 --> 00:11:57,000 See the output. You are getting like a Boolean. Not only for 211 00:11:57,000 --> 00:12:05,100 that, 'print(my_new_value, type(my_new_value))'. See the 212 00:12:05,100 --> 00:12:07,100 output. Both are Boolean. 213 00:12:07,900 --> 00:12:10,800 So actually whenever if you write in this way, you will feel 214 00:12:10,800 --> 00:12:13,800 that 'True' is a string and 'False' is also a string, 215 00:12:13,800 --> 00:12:17,100 but if you don't write quotations only for these two words 216 00:12:17,100 --> 00:12:20,900 guys, not for any other words, only for 'True' and 217 00:12:20,900 --> 00:12:22,500 only for 'False', 218 00:12:23,000 --> 00:12:27,300 if you don't write quotations, then they will act as like 219 00:12:27,300 --> 00:12:28,800 a Boolean data type. 220 00:12:29,400 --> 00:12:32,800 By mistake if you write quotations for 'True', if you write 221 00:12:32,800 --> 00:12:35,700 anything inside of a quotation that is always a string 222 00:12:35,700 --> 00:12:38,700 even though if it is 'True', because you have written inside of 223 00:12:38,700 --> 00:12:42,500 quotations now that data will be considered as a string. 224 00:12:42,500 --> 00:12:44,100 Observe the output. You're getting as a string. 225 00:12:44,100 --> 00:12:46,700 [no audio] 226 00:12:46,700 --> 00:12:51,300 Right. So you have to remember this point. Except this 'True' and 227 00:12:51,300 --> 00:12:53,400 'False', remaining all strings 228 00:12:53,400 --> 00:12:59,800 you have to write quotations, then only that is a valid syntax. 229 00:13:01,400 --> 00:13:04,100 Even if you want to take 'True' as a string, 230 00:13:04,100 --> 00:13:07,100 yes, you can take it by mentioning inside of quotations. 231 00:13:07,800 --> 00:13:12,800 Right. So guys, these are the data types, basic data types in your Python. 232 00:13:13,800 --> 00:13:19,600 Right. So already we know that. The next thing is typecasting or 233 00:13:19,600 --> 00:13:20,600 type conversion, 234 00:13:21,600 --> 00:13:25,800 so simply converting one data type to another, is it possible? 235 00:13:25,900 --> 00:13:26,900 Yes, it is possible. 236 00:13:27,200 --> 00:13:28,800 Let me show you one example. 237 00:13:28,800 --> 00:13:32,600 [no audio] 238 00:13:32,600 --> 00:13:35,500 See as of now let me take a very simple example so that 239 00:13:35,500 --> 00:13:36,600 you will be clear. 240 00:13:36,600 --> 00:13:43,500 [no audio] 241 00:13:43,500 --> 00:13:47,200 I am taking 'x=' some number 56, right? 242 00:13:47,300 --> 00:13:51,300 And then I am printing your 'x', then its 'type(x)'. 243 00:13:51,300 --> 00:13:53,200 [no audio] 244 00:13:53,200 --> 00:13:56,200 Observe the output first, integer. Now 245 00:13:56,200 --> 00:14:02,600 I am taking y, 'y=str(x)', then I am printing 246 00:14:03,000 --> 00:14:07,800 'y, type(y)', so whatever the 'y' you have no, 247 00:14:08,100 --> 00:14:11,000 that 'y' how you are creating? From 'x' 248 00:14:11,000 --> 00:14:14,500 I'm creating 'y' but while assigning 'x' value to 'y' I am 249 00:14:14,500 --> 00:14:20,000 converting the number into string. Now see the output. Yes, 250 00:14:20,000 --> 00:14:24,000 now your '56' is a string. That means 'y' value is a string 251 00:14:24,000 --> 00:14:25,200 but 'x' value is integer. 252 00:14:25,200 --> 00:14:27,000 [no audio] 253 00:14:27,000 --> 00:14:28,300 Right. Same way 254 00:14:28,800 --> 00:14:34,300 let me take 'x=', some 'z=', boolean, 255 00:14:34,300 --> 00:14:41,700 'bool(x)', and let me print your 'z' as well as 'type(z)'. 256 00:14:41,700 --> 00:14:43,700 [no audio] 257 00:14:43,700 --> 00:14:48,800 See the output. 'True' you're getting. 'bool(x)'. Some value 258 00:14:48,800 --> 00:14:51,300 is there, that value if you convert into 'z', 259 00:14:51,300 --> 00:14:54,800 I mean Boolean, that will be 'True'. 260 00:14:54,800 --> 00:14:59,300 Let me take 'p=0', right and first let me print 261 00:14:59,300 --> 00:15:01,300 your 'p', then 'type(p)'. 262 00:15:01,800 --> 00:15:04,100 So I want to print 'p' as well as 'type(p)'. 263 00:15:04,600 --> 00:15:07,300 So observe the last 'print' statement, that is a integer. Now, 264 00:15:07,300 --> 00:15:13,600 what I am doing is, let me take some 'q= bool(p)'. 265 00:15:13,600 --> 00:15:19,400 Now let me print in the next line 'q, type(q)'. 266 00:15:19,400 --> 00:15:20,700 It is a 'False'. 267 00:15:20,700 --> 00:15:22,900 [no audio] 268 00:15:22,900 --> 00:15:23,900 Right. 269 00:15:24,300 --> 00:15:26,500 Okay, how you are getting 'True' or 'False', I will explain to you 270 00:15:26,700 --> 00:15:29,200 but before that you are converting one data type to another 271 00:15:29,200 --> 00:15:33,900 data type, string, integer to string, right or string to Boolean 272 00:15:33,900 --> 00:15:34,900 also you can convert. 273 00:15:36,100 --> 00:15:40,100 Okay, now let me give the helping words to convert one data type 274 00:15:40,100 --> 00:15:41,000 to other data type. 275 00:15:41,000 --> 00:15:43,900 [no audio] 276 00:15:43,900 --> 00:15:47,000 So guys in your data types, in your Numbers data type you have - 277 00:15:47,000 --> 00:15:50,200 int, float, and then complex; 278 00:15:51,600 --> 00:15:54,700 Strings - str; and then boolean - bool. 279 00:15:54,700 --> 00:15:58,000 So these are the helping words to convert from one data type 280 00:15:58,000 --> 00:16:00,500 to another data type, right? 281 00:16:00,600 --> 00:16:04,500 Let's say, now I can easily explain from terminal guys. 282 00:16:04,500 --> 00:16:07,600 Let me write 'x=4.6'. Now 283 00:16:07,600 --> 00:16:10,000 I am printing directly 'int(x)'. 284 00:16:11,700 --> 00:16:13,900 That is float. Fractional 285 00:16:13,900 --> 00:16:14,900 part will be removed, 286 00:16:16,000 --> 00:16:22,300 right. Now I have, let's say 'my_name=' some "python". 287 00:16:22,800 --> 00:16:25,600 Now you know what is the type of your 'name'. 288 00:16:27,200 --> 00:16:31,200 Right. I'm printing your name as well as 'type()', your name. 289 00:16:31,900 --> 00:16:33,700 String, right. Now 290 00:16:33,700 --> 00:16:36,800 I am trying to convert that string into integer. 291 00:16:38,000 --> 00:16:41,900 So, how can I convert? Simply 'int()', your variable. 292 00:16:41,900 --> 00:16:43,400 It is giving an "invalid 293 00:16:44,900 --> 00:16:49,500 literal for int() with base 10", because, see guys number 294 00:16:49,500 --> 00:16:52,500 4 if you write inside of quotations that will convert 295 00:16:52,500 --> 00:16:53,700 as a string, 296 00:16:54,800 --> 00:16:59,200 but if you remove quotations for "python", because this is the 297 00:16:59,200 --> 00:17:01,500 alphabets, right, alphabets 298 00:17:01,500 --> 00:17:04,800 you cannot convert into number but number you can convert into strings. 299 00:17:05,200 --> 00:17:07,000 So this is a very, very important point. 300 00:17:07,000 --> 00:17:10,200 [no audio] 301 00:17:10,200 --> 00:17:17,800 First thing, any data type can be converted into Boolean, first 302 00:17:17,800 --> 00:17:21,500 thing. This is always true. With the help of simply 303 00:17:21,500 --> 00:17:24,700 'bool(any_data_type)' 304 00:17:26,400 --> 00:17:29,800 is maybe 'True' or 'False'. 305 00:17:30,700 --> 00:17:33,200 So when it will become 'True' or when it will become 'False'? 306 00:17:33,900 --> 00:17:36,099 So 'bool(empty)' is always 307 00:17:36,099 --> 00:17:38,800 [no audio] 308 00:17:38,800 --> 00:17:39,800 'False', 309 00:17:39,800 --> 00:17:43,400 [no audio] 310 00:17:43,400 --> 00:17:46,500 okay and 'bool(non-empty)' data 311 00:17:46,500 --> 00:17:50,099 [no audio] 312 00:17:50,099 --> 00:17:51,099 is always 'True'. 313 00:17:52,300 --> 00:17:53,500 Let me give the examples, 314 00:17:53,500 --> 00:17:56,600 what is empty and what is non-empty. '0', 315 00:17:57,100 --> 00:17:59,500 nothing right. '0' is nothing. 316 00:18:00,100 --> 00:18:02,300 So let me show you on your terminal. 317 00:18:03,900 --> 00:18:06,800 'bool(0)' is always 'False'. 318 00:18:07,400 --> 00:18:11,000 Let's say I am defining a string which is empty. See immediately 319 00:18:11,000 --> 00:18:12,800 I started and closed with quotations, 320 00:18:12,800 --> 00:18:15,300 that is a, that is an empty string. 321 00:18:16,500 --> 00:18:20,200 And I'm trying to convert that string into Boolean, 'False', 322 00:18:21,300 --> 00:18:22,400 right. Guys, 323 00:18:22,400 --> 00:18:24,700 there is one more data type called 'None', nothing. 324 00:18:24,700 --> 00:18:31,100 So 'bool(None)' is also 'False', and while going forward 325 00:18:31,100 --> 00:18:35,200 we will see something like this. As of now, don't worry. Just 326 00:18:35,200 --> 00:18:36,500 observe. This is also empty. 327 00:18:36,500 --> 00:18:40,600 I am not writing anything inside of your curly braces, right? 328 00:18:40,600 --> 00:18:42,800 [no audio] 329 00:18:42,800 --> 00:18:44,300 Sorry, your brace. 330 00:18:44,300 --> 00:18:47,100 [no audio] 331 00:18:47,100 --> 00:18:49,500 Okay, so what is that 332 00:18:49,500 --> 00:18:52,100 we will see. Now for empty 333 00:18:52,100 --> 00:18:53,300 I am giving example 334 00:18:53,300 --> 00:18:56,200 [no audio] 335 00:18:56,200 --> 00:18:57,500 'bool(0)', 336 00:18:57,500 --> 00:18:59,400 [no audio] 337 00:18:59,400 --> 00:19:03,200 'bool(None)', 'None' is also one of the data types, nothing, 338 00:19:04,700 --> 00:19:08,100 'bool([])', some list this is, 339 00:19:08,100 --> 00:19:14,800 empty list and 'bool()', let me write empty tupple, 340 00:19:15,700 --> 00:19:19,200 and then 'bool()', empty dictionary. 341 00:19:19,400 --> 00:19:20,900 So what is the dictionary, tupple list 342 00:19:20,900 --> 00:19:24,600 we will see. So these all results guys will always give 343 00:19:24,600 --> 00:19:29,200 output as 'False'. Remaining combinations, if something is there 344 00:19:29,400 --> 00:19:31,600 and if you convert that into Boolean it will give 'True'. 345 00:19:32,200 --> 00:19:35,400 So guys, these are very, very important in your real-time. 346 00:19:35,600 --> 00:19:38,400 While writing our scripts we'll come to know how much importance 347 00:19:38,400 --> 00:19:40,700 is there with conversion of any data into Boolean, 348 00:19:41,900 --> 00:19:44,700 okay. Now one more point you have to remember, 349 00:19:44,700 --> 00:19:46,600 [no audio] 350 00:19:46,600 --> 00:19:47,600 any data type 351 00:19:47,600 --> 00:19:50,400 [no audio] 352 00:19:50,400 --> 00:19:51,600 can be converted 353 00:19:53,300 --> 00:19:59,400 into a string but reverse is not always true. 354 00:19:59,400 --> 00:20:02,300 [no audio] 355 00:20:02,300 --> 00:20:05,200 The reason is number can be converted into string, 356 00:20:06,800 --> 00:20:12,000 right and string which consists of alphabets, that string 357 00:20:12,000 --> 00:20:13,600 you cannot convert into number. 358 00:20:14,300 --> 00:20:19,100 Let's say 'x=', directly I'm writing a string called 359 00:20:19,100 --> 00:20:21,300 "345". Now "345" is a string. 360 00:20:22,200 --> 00:20:25,800 So what is the use of writing your number as a string means 361 00:20:25,800 --> 00:20:28,500 sometimes, you know, you are going to take versions in 362 00:20:28,500 --> 00:20:31,000 this way. Version is always a string guys. 363 00:20:31,800 --> 00:20:33,200 You have to take as a string. 364 00:20:33,700 --> 00:20:36,000 If you are going to work with, in your real time with any 365 00:20:36,000 --> 00:20:40,100 version please be careful, try to define your 366 00:20:40,100 --> 00:20:42,200 version always as a string. 367 00:20:43,600 --> 00:20:47,500 And even while working, while writing your Python Script, right 368 00:20:47,500 --> 00:20:49,500 to get some version of some particular software 369 00:20:49,500 --> 00:20:50,900 you will get as a string only. 370 00:20:52,400 --> 00:20:56,500 That's why try to write your version as a string, 371 00:20:57,600 --> 00:20:58,600 right. That's fine. 372 00:20:58,700 --> 00:21:02,900 Now see that. What will happen if I define any number inside 373 00:21:02,900 --> 00:21:04,200 of quotations, right. 374 00:21:05,800 --> 00:21:09,100 Now, do we have a number called 2.1.3.5 375 00:21:09,100 --> 00:21:11,700 in our number systems? No. You have something like 376 00:21:11,700 --> 00:21:14,800 this but you don't have multiple dots in your number systems. 377 00:21:14,800 --> 00:21:18,100 That's why you cannot convert whatever the 'x' you are having 378 00:21:18,100 --> 00:21:23,600 as of now into your, see suppose if I take 379 00:21:23,600 --> 00:21:25,500 [no audio] 380 00:21:25,500 --> 00:21:28,400 2.1.3.5 is not a base 10 number system. 381 00:21:28,500 --> 00:21:29,700 It is something else. 382 00:21:29,900 --> 00:21:33,100 That's why that you cannot convert into a number. 383 00:21:33,900 --> 00:21:38,400 But if I take 'x=', some 45. This is a number but you 384 00:21:38,400 --> 00:21:41,700 represented that as a string because you have written inside 385 00:21:41,700 --> 00:21:45,200 of quotations, but I can convert that into integer directly 386 00:21:45,200 --> 00:21:48,200 by writing 'int(x)' because 45 is there 387 00:21:48,200 --> 00:21:51,600 even in your number systems also, that's why you can convert 388 00:21:51,600 --> 00:21:55,300 that into integer, right? 389 00:21:55,400 --> 00:21:59,900 So this is the case for this meaning. 390 00:21:59,900 --> 00:22:04,100 I mean any data type can be converted into string but reverse 391 00:22:04,100 --> 00:22:05,100 is not always true. 392 00:22:05,200 --> 00:22:09,500 Sometimes it is true whenever if the string is a valid number 393 00:22:09,500 --> 00:22:10,500 system data, 394 00:22:11,800 --> 00:22:16,700 right. Okay guys, so this is the way how you can convert from 395 00:22:16,700 --> 00:22:19,800 one data type to other data type and this is called type 396 00:22:19,800 --> 00:22:22,000 casting or type conversion, okay. 397 00:22:22,400 --> 00:22:24,600 Okay guys thank you for watching this video. 398 00:22:24,600 --> 00:22:33,000 [no audio]