top of page

Conversion

Data Types: Numbers

Data Types: Strings

Concatenation

Conversion

Data Types: Booleans

Checkpoint

Summary

It is possible to convert from one data type to another with the commands float()int(), and str().

 

Operations combining different numerical data types together can also convert between the data types:

Int + Int

Float + Float

Int + Float

Int

Float

Float

Let's try converting between different data types:

1 # Convert a string to a float

2 x = float("3")

print(type(x))

# Convert an int to a string

5 x = str(4)

6 print(type(x))

7 # Convert a float to an int

8 x = int(4.0)

9 print(type(x))

bottom of page