Home > Backend Development > Python Tutorial > Type Casting Par-06

Type Casting Par-06

WBOY
Release: 2024-08-31 14:37:21
Original
1006 people have browsed it

Type Casting Par-06

I'm bored sitting in front of the computer. The brain needs a little refreshment. So I went out for a walk in the afternoon. walking on the road Loud noise of cars around. These words are ringing in the ears. Coming to seek a little peace comes great turmoil. So I came a little away from the city, there is no loud noise of cars. Pleasant environment. The place is like a jungle. There are many plants around. The trees are very large in size. Estimated age will be 30-40 years. There are a few that are a little smaller in size. Maybe 10-15 years old.

The place looks great. Came here in early spring. A gentle breeze is also blowing. When falling on the body, a strange sensation is created in the soul. feels good It would have been better to have someone special with you. After walking around for a while, I saw a broken house. Very old house, about 50-60 years ago. Wanted to take a look at the house. So I entered the house. Inside is a bit dark. After wandering around the house for a while, I saw something like a round coin lying down. What is this again? I picked it up with my hand and it looked like a coin but a little thicker. What could be the thing?

Wait a second, I'm here to hang out. There is no point in stressing about these things. For this, I put the object in my pocket and started walking around.

Anyway it feels good. The brain is completely fresh. I suddenly remembered that I was supposed to publish a blog today. But I completely forgot. Nothing was written. So I got out of there. Time took a little longer. By the time it was evening.

It is 6 pm. When I first came and washed my hands and face, I remembered the object in my pocket. The thing is very dirty. I tried to wash it with water. Nothing happened. No, it won't be this way. Something different needs to be done. How about toothpaste?

I started working with toothpaste and an old brush. The first time I applied toothpaste and brushed the brush for a while. Cleared up a bit. I did the same for a few more. Clear is going well. This is how it goes. After a while, the toothpaste stops coming out. I understand that the toothpaste is over.

Cleaning up pretty well now. Chuck is chucking. It looks very white. Like gray color. The object looks like something silvery but I'm not sure. If there was a piece of gold somehow, I'd sell the thing and become a big man, then get up on my feet and run a supercomputer. But it doesn't seem like it will. Gold is no longer gray in color. I didn't buy a supercomputer anymore.

Well, if instead of one, there were thousands of the same kind of things, then the rest of the life would be spent rubbing the brush like this. How about making a machine for this? I will put the money in and return it to me. It would be nice to have a machine like this.

But it's not going well for me. I have only one object and that I have already cleared. I don't need such a machine.

I left everything and sat in front of the computer. I will write the blog.

Today's topic is Type Casting in Python. If you read the above story then you already understand the concept of type casting. Simply put, Type Casting is changing the data type of data.

Now if I ask you what is the data type of "200"?

Answer is very simple it is number. No, it's not a number. If you notice, you can see the number inside the quotation. And whatever is inside the quotation is a String.

Now what if you are asked to convert it to a number?

It's also easy, I'll give you the quotation.

Your answer is correct. But the problem will arise, if I change the question a bit.

Suppose you are building a software, where you need to input data. It should be taken at no.

What to do now? You can't get quotations here.

If you give an example you can understand the subject.

age = '20'
print(type(age))
Copy after login

Here the output will be . Now it needs to be converted to integer. But the condition is that the code cannot be touched in the first line.

Python has a function int() to do this. Copy and run the following code.

age = '20'
ageInteger = int(age)
print(type(ageInteger))
Copy after login

What is the output?

In addition to the int() function, there are two more functions.

  • The float() function is used to convert the float data type to .
  • str() function is used to convert string to data type .

Now you will practice the remaining two and give their screenshot in the comments.

Let's finish writing the blog.

A friend of mine called and exchanged words for a while. At some point in the conversation, I found out that he had a machine to clean the object I had received. I scolded Shala. If I had told earlier, my toothpaste would not have been wasted. The time was also chosen. Have to buy new tooth paste again.

The above is the detailed content of Type Casting Par-06. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template