Data type conversion, also known as type casting, refers to the process of changing a value from one data type to another. In Python, this can be done implicitly or explicitly. Python automatically converts a value from one data type to another in certain situations, often to avoid errors or loss of information. This is called implicit conversion or type coercion. For example, when adding an integer and a float, Python will implicitly convert the integer to a float before performing the addition.
00:00Hello guys, Angleys, welcome back and good morning.
00:07You can see the last lecture in the input function that we have asked if we can change the type of variable.
00:15For example, I will show you 5 enter and execute the type of function.
00:22So, you can tell me that 5 enter is a number.
00:29However, what if we just need a number?
00:34That's why we can do simple type conversion.
00:38For example, we have a type function, input function.
00:43We have a str function.
00:46You have a str function.
00:48So, str function, which variable is called,
00:52or which variable is called,
00:56So, this variable, whether it is a string or an integer,
00:59it will convert it to a string.
01:01So, you have to know that this input is already done.
01:04So, let's do this.
01:05Let's do this.
01:06Let's do this.
01:07Let's do this.
01:08Let's do this.
01:09Let's do this.
01:10Let's do this.
01:11Let's do this.
01:13So, let's do this in the user.
01:16Let's say, we define a number and say num underscore 1 is equal to let's say 2.
01:23That is a number.
01:24And the other num underscore 2, we input from users.
01:28And remember, input is basically num data type change, string convert.
01:33So, I say please enter a number.
01:38Make sense?
01:40Okay.
01:40Now simple, we do print.
01:43And print, I say num1 plus num2.
01:49So, I just add two numbers.
01:51However, one of the input function is number.
01:54Now, I enter 2 and add 2.
01:58So, this is the reason I have told you that these two values are different data types.
02:06If I print the type function and call the type function, I give the num2 value to the input and execute it.
02:20So, you can see that the type function is a string.
02:24And then there is num2 and then there is num2 and then there is num2 and then you will see the difference in the data type.
02:39And you will see the error reason.
02:43Now, that's the reason you can do it.
02:45You will see the type function function function function function function function function function function function function.
02:47Now, the problem is that you can change the type if there is string, then it will be int function and if there is integer type in string, then it will be str.
03:00So, now I will see two examples.
03:02In this case, this convert in string, then I will convert it into integer.
03:08So, it will be int function call.
03:12Now, the int function will give you all the value.
03:17You will convert into int.
03:21Now, if I run it, then I will run it.
03:25Then we get the result for.
03:29The reason is that the two types are integer.
03:33Excellent, right?
03:35So, if you have a value, for example, here we have a string.
03:41Now, if I remove it, I will remove it.
03:45Now, if I remove it, I will remove it.
03:48Now, I will run it again.
03:50Then I will run it again.
03:52Then I will enter it.
03:53Then I will get error.
03:54The reason is that the first data is the type of integer.
03:57If I convert this integer into string, then I will call it.
04:00Then I will default to the number.
04:01So, I will replace it all.
04:02You will come this way.
04:03Then I will call it into string.
04:05Now, I will see that it left the number of integer.
04:07Now, it has a string being called.
04:10However, now the result is 4.
04:12Why does it not?
04:13You will get 2 strings happening.
04:15It will not be two strings.
04:172 strings are concatenate.
04:18So, which would be no number of integer is,
04:20that will be called, which will not be compared.
04:22Then you will not have the result.
04:24Ad not be as much.
04:25Then I will take this back.
04:26Now, you will focus more on string.
04:272 is our string, if I add 2, then there will be 22 results.
04:31Because 2 and 2 will be joined, 2 and 2 will not merge, add not.
04:38Two concepts we have learned.
04:40We have learned how to convert one string and how to convert one string.
04:47We have learned how to convert one string and how to convert one string.
Be the first to comment