In some situations, you will need to modify the
datatype of a variable. So for example, you want
to change an integer to a float or an integer to a
Boolean, String to float, etc. And we have actually
a good example here to work on. The input function,
as you saw before, always returns a string. Okay,
even if you give a number, so then if you need to
work with the number you got from the input,
you're going to have a problem because well, this
number will actually be a string, not a number. So
you need to change the type for the variable and
this is called cast, okay. You are going to cast
the type. And to cast a variable, it's very easy.
Okay, so let's say we have an example, let's say
you want to cast a string, okay, to so we have the
string here, a is a string. So if I do type a, I
have a string, I want to cast a to an integer. In
this case, I simply do int a, okay, you simply
use the final data type you want. And then in
parentheses, you put the variable or the value you
have no, okay. If I do int a, you can see now I
have 67, without the quotes. And if I do type int,
a, now this is of class int. So this way, you can
change a value here, from whatever data type it is
to the data type int. You can also do the reverse,
if you want, you can cast something into a string.
Let's say I want to cast 34. This is going to give
the string 34. You can cast it to float for
example, float from three is going to give 3.0. You
can do the opposite int let's say 3.0 is going to
be 3 and let's see, for example 3.7. What do
we have here, we have just three okay. This is
important when you cast a float number to an
integer number, the number is going to be
truncated. Okay, so whatever is after the comma is
going to be last. Okay, so that's important to
know. And then so we can also cast a boolean to an
integer, let's see that int True, is going to
give one an int False is going to give zero.
Okay, so actually, if you want to see a Boolean
with numbers, well when you have zero is going to
be False. If you have one is going to be True, but
in fact, if you have any other number is going to
be True. Okay, if you want to do let's say bool,
from 34, is going to be to bool from minus one is
going to be True. The only value which is going to
give False is zero. Alright, and with that, you
can cast any type to any other type.