determine variable type
Scott David Daniels
Scott.Daniels at Acm.Org
Thu Aug 18 15:56:03 EDT 2005
MCollins at seminolecountyfl.gov wrote:
> trying to determine a variable type, specifically that a variable is an
> integer.
>
> i tried using type(var) but that only seemed to produce a response in the
> command line.
>
> is there a built in python function to determine if a variable is an
> integer?
if isinstance(var, (int, long)):
print 'var (%r) is an integer' % var
elif isinstance(var, float) and int(var) == var:
print 'var (%r) is a float that could be an integer' % var
else:
print 'var (%r) is not an integer' % var
--Scott David Daniels
Scott Daniels at Acm.Org
More information about the Python-list
mailing list