+ 1
how i can change type of float to the integer in this code,,,,,,,, x = 9 y = 3 print (x/y)
4 ответов
+ 2
Use the built-in function: int()
x = 9
y = 3
print(int(x/y))
This thing is called 'Type Casting'. By using the int() function, you changed the float data type to an integer.
+ 1
Have you looked up about casting in python?
It's quite easy. I'm sure you can find many resources online:
https://code.sololearn.com/W0uW3Wks8UBk/?ref=app
https://www.sololearn.com/discuss/2521875/?ref=app
https://www.sololearn.com/discuss/1593053/?ref=app
https://www.sololearn.com/discuss/2939846/?ref=app
https://www.sololearn.com/discuss/3004480/?ref=app
+ 1
You can use int or use floor division(//)
Example:
print(5//2) gives output 2
+ 1
x = 9
y = 3
result = int(x / y) #result = float(x / y)
print(result)