SnipBits

How to check if a variable is a number in Python.

we can check a variable if is an Integer or not using the type() function, we can pass the variable as an argument , and we compare the result to the int class:

variable_1 = 1
type(age) == int #True

we can check if the number is a floating number by comparing it to the float Class instead of int

fraction = 0.1
type(fraction) == float #True

Maher Gallaoui

You like our Content? Follow us to stay up-to-date.