Python
Python Type Conversion
AKA.DM
2024. 9. 11. 07:51
반응형
Data types can be converted to each other in Python.
The funtions we can use for type conversions are indicated below
To convert to string ==> str()
To convert to integer ==> int()
To convert to float ==> flaot()
Let's have a variable named example with a float value of 5.8 in it.

To convert this variable to integer, you can use the int() function as follows.
To summarize; We conveted the example variable to an integer value with the int funtion and equated it to the "converted example" vairable. Then we got the output with the print funtion.

We may not be able to make every type change we want.
For example, if there isn't only a number in a string value, we cannot convert this value to an integer. We get Value error.

반응형