OneBite.Dev - Coding blog in a bite size

convert variable from float to int in python

Code snippet on how to convert variable from float to int in python

a_float = 5.3

a_int = int(a_float)

This code helps to convert a float number to an integer. The first line stores a float number in the variable named “a_float”. The second line uses the built-in int() function to convert the float number stored in “a_float” to an integer and assigns it to the variable “a_int”. The value stored in “a_int” is the same as the value stored in “a_float”, but in the form of an integer instead of a float.

python