Reputation: 942
In python 2.6 and 2.7 you use
isinstance(variable, (int, long))
In python 3x ints and longs are merged. So you simply do
isinstance(variable, int)
Is there a clean version agnostic way of testing if a variable is an integer in python?
Upvotes: 1
Views: 77
Reputation: 142206
From 2.6 you can use numbers.Integral:
if isinstance(var, numbers.Integral):
pass # whatever
Upvotes: 2