How To Convert Data Types in Python ?

Python

Nicesnippets

06-12-2021


How To Convert Data Types in Python ?

Hello Friends,

Now let's see example of how to convert data types in python. I am going to show you python convert data type. We will learn convert data types using python.

In Python, data types are used to classify one particular type of data, determining the values that you can assign to the type and the operations you can perform on it.

Here I will give example for how to convert data type in python. So let's see the below example:

Example 1 : Convert In Float


f = 123

print(float(f))

Output:

123.00

Example 2 : Convert In Integer

num = 123.80

print(int(num))

Output:

123

Example 3 : Convert In String

num = 9872

print(str(num))

num2 = 5689.456

conNum2 = str(num2)

print(conNum2)

Output:

'9872'

'5689.456'

Example 4

num1 = "98"

num2 = "200"

res = int(num2) - int(num1)

print(res)

Output:

102

It will help you....

how to convert data types in python, python convert data types example, convert data type to string python, how to change the data types in python, convert data type in python,python convert data type


Recommended Posts