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.

 

 

 

 

반응형

'Python' 카테고리의 다른 글

Methods in Strings in Python  (0) 2024.09.24
Boolean Logic Expression in Python  (0) 2024.09.21
Eascape Sequence Opertations in Python  (0) 2024.09.20
Python Print Function  (0) 2024.09.19
Arithmetic Operation in Python  (0) 2024.09.13