Sometimes, we want to check whether a variable is an integer or not with Python.
In this article, we’ll look at how to check whether a variable is an integer or not with Python.
How to check whether a variable is an integer or not with Python?
To check whether a variable is an integer or not with Python, we can use the isinstance
function.
For instance, we write
isinstance(foo, int)
to check if the value of variable foo
is an int by calling isinstance
with foo
and int
.
Conclusion
To check whether a variable is an integer or not with Python, we can use the isinstance
function.