import math myInt = int(10) myFloat = float(10.0000001) mySignedFloat = float(-1.5253) print(myInt) print(myFloat) #Casting is when we convert one type to another. #We can use the int and float constructors to convert the values. print('I will cast the float to an int!') #Keep in mind that this will round up, not round down. #If you want to round down, you have to use the floor function. print(int(myFloat)) #example of how to round down. print(math.floor(myFloat)) print(math.floor(mySignedFloat)) print('I will cast the integer to a float!') print(float(myInt))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question