We have another important thing in Python that is called casting.
What is casting?
Casting is changing one type to another type.
For example, we have integer.
I want to change it to string.
Okay.
Or I have integer I want to change it to float.
I have float I want to change it to integer.
How can I do this.
Okay.
Let me come right here and create a new file.
Let's name it cast.py.
Okay.
So for doing that we use those functions like int is changing anything to integer like float is changing
anything to float like str method.
It will change anything to any number to string or any string to string okay.
Let's see.
We have x is equal to 12.
Now let's print type of this okay.
Type of x.
Save it and come here.
Use clear and use Python.
cast.py hit enter.
You see it is integer right now.
And now I am going to use x is equal to is to r and then x.
Okay.
It is one way that you can change it.
Okay.
You may ask what is this thing.
Or if there's a little complex for you I can use it another way too.
Okay.
Now I can give instead of x here 12.
That is also the same.
Or I can give x which has a value.
Value is 12.
Again I will just change the type and again store it into the x variable.
And here I'm printing type of the x.
Now.
Here let's see.
Okay now you see it is giving me store y.
As you see right now we have a number here.
But why it is giving me store is not a string.
Come on.
Of course it is a string because we use str method right here.
Okay, now it is casted or it is changed.
Type of this change to string okay.
We can use this kind of thing in a lot of places okay.
Or I have name which is equal to name add.
And now if I print type of this which is.
Name okay.
And you see it is giving me a string.
And what if I change the type of this.
How can I use str?
Or of course it is str.
I want to change it to integer.
Let's see.
Is it possible or not?
Okay.
No, it is not invalid literal for integer with base ten okay.
You cannot change a string to an integer okay.
It's not possible.
So never try to use it.
Okay.
You cannot change string to a number, but you can change a number to a string.
Okay so let's remove this.
Okay I can save it I can execute this.
It will give me a string.
Okay.
Very good.
You learn how to cast something to another.
Okay I type to another type.
So let's go and see what is next.