MeshWorld India LogoMeshWorld.

How to Check if a Variable is an Integer in Python

Listen to ArticleAI Speech
~2 min read narration
100%
How to Check if a Variable is an Integer in Python

We’ve listed below two different ways to check whether variable contains integer value or not.

  • Using type() function
    • It accepts operand(variable or value) as an argument and return it’s data-type.
    • Return value can be used to with int class.
  • Using isinstance() function
    • We pass first argument as operand(variable or value) and second argument as int class.

In this article we’ll see how to check if a variable is an integer. Let us understand also with an example.

Check Python variable is of an integer type or not

Method 1 using type() function

Passing the variable as an argument, and then comparing the result to the int class.

age = 12
type(age) == int
# True

age = 12.24
type(age) == int
# False

age = '12.24'
type(age) == int
# False

Method 2 using isinstance() function

Passing variable as first argument, and int class as second argument.

age = 12
isinstance(age, int)
# True

age = 12.24
isinstance(age, int)
# False

age = '12.24'
isinstance(age, int)
# False

Even comparing float type of value with int class, either by using type() or isinstance() function, will give False as resultant value. Same for value '12.24' enclosed in single quotes.

Hope you like this!

Keep helping and happy 😄 coding

Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Vishnu
Primary Author

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive