WEBVTT

00:01.080 --> 00:06.400
We have another important thing in Python that is called casting.

00:06.560 --> 00:07.520
What is casting?

00:07.880 --> 00:10.360
Casting is changing one type to another type.

00:10.400 --> 00:12.320
For example, we have integer.

00:12.600 --> 00:13.880
I want to change it to string.

00:14.040 --> 00:14.720
Okay.

00:14.760 --> 00:17.160
Or I have integer I want to change it to float.

00:17.200 --> 00:19.040
I have float I want to change it to integer.

00:19.560 --> 00:20.920
How can I do this.

00:21.120 --> 00:21.760
Okay.

00:21.800 --> 00:25.560
Let me come right here and create a new file.

00:25.600 --> 00:28.320
Let's name it cast.py.

00:28.360 --> 00:28.760
Okay.

00:29.360 --> 00:40.120
So for doing that we use those functions like int is changing anything to integer like float is changing

00:40.120 --> 00:42.920
anything to float like str method.

00:43.000 --> 00:48.200
It will change anything to any number to string or any string to string okay.

00:49.360 --> 00:49.800
Let's see.

00:49.800 --> 00:53.000
We have x is equal to 12.

00:53.040 --> 00:55.840
Now let's print type of this okay.

00:56.360 --> 00:57.880
Type of x.

00:58.440 --> 01:01.360
Save it and come here.

01:01.360 --> 01:04.920
Use clear and use Python.

01:04.920 --> 01:07.000
cast.py hit enter.

01:07.000 --> 01:08.680
You see it is integer right now.

01:09.440 --> 01:17.310
And now I am going to use x is equal to is to r and then x.

01:17.590 --> 01:17.990
Okay.

01:18.550 --> 01:20.790
It is one way that you can change it.

01:21.310 --> 01:21.550
Okay.

01:21.550 --> 01:23.190
You may ask what is this thing.

01:24.150 --> 01:28.950
Or if there's a little complex for you I can use it another way too.

01:28.990 --> 01:29.950
Okay.

01:29.950 --> 01:34.030
Now I can give instead of x here 12.

01:34.070 --> 01:35.270
That is also the same.

01:35.590 --> 01:38.590
Or I can give x which has a value.

01:38.630 --> 01:39.870
Value is 12.

01:39.910 --> 01:44.710
Again I will just change the type and again store it into the x variable.

01:44.710 --> 01:47.350
And here I'm printing type of the x.

01:47.870 --> 01:48.350
Now.

01:51.590 --> 01:53.070
Here let's see.

01:54.310 --> 01:57.350
Okay now you see it is giving me store y.

01:57.870 --> 02:00.070
As you see right now we have a number here.

02:00.070 --> 02:03.870
But why it is giving me store is not a string.

02:04.870 --> 02:05.590
Come on.

02:05.630 --> 02:10.470
Of course it is a string because we use str method right here.

02:10.590 --> 02:14.510
Okay, now it is casted or it is changed.

02:14.550 --> 02:18.070
Type of this change to string okay.

02:18.110 --> 02:22.430
We can use this kind of thing in a lot of places okay.

02:22.430 --> 02:26.180
Or I have name which is equal to name add.

02:26.460 --> 02:32.220
And now if I print type of this which is.

02:34.820 --> 02:35.700
Name okay.

02:38.220 --> 02:40.620
And you see it is giving me a string.

02:41.220 --> 02:44.540
And what if I change the type of this.

02:44.980 --> 02:47.860
How can I use str?

02:48.420 --> 02:49.660
Or of course it is str.

02:49.660 --> 02:51.020
I want to change it to integer.

02:51.260 --> 02:51.740
Let's see.

02:51.860 --> 02:53.460
Is it possible or not?

02:56.220 --> 02:56.780
Okay.

02:58.900 --> 03:04.180
No, it is not invalid literal for integer with base ten okay.

03:04.460 --> 03:08.900
You cannot change a string to an integer okay.

03:08.940 --> 03:10.580
It's not possible.

03:10.700 --> 03:12.180
So never try to use it.

03:12.220 --> 03:12.380
Okay.

03:12.380 --> 03:17.940
You cannot change string to a number, but you can change a number to a string.

03:17.980 --> 03:20.940
Okay so let's remove this.

03:22.700 --> 03:25.220
Okay I can save it I can execute this.

03:26.180 --> 03:27.500
It will give me a string.

03:27.540 --> 03:27.940
Okay.

03:28.220 --> 03:29.060
Very good.

03:29.060 --> 03:32.100
You learn how to cast something to another.

03:32.140 --> 03:33.780
Okay I type to another type.

03:34.140 --> 03:36.460
So let's go and see what is next.
