Three ways to view digital data:
[1] isinstance is more readable
#! /Usr/bin/ENV python <br/> ''' typechk. PY ''' <br/> def displaynumtype (Num): <br/> Print num, 'is ', <br/> If isinstance (Num, (INT, long, float, complex): <br/> Print 'a number of type: ', type (Num ). _ name __< br/> else: <br/> Print 'not a number at all! '<Br/> displaynumtype (-69) <br/> displaynumtype (99999999999999999999l) <br/> displaynumtype (99999999999999999999) <br/> displaynumtype (98.6) <br/> displaynumtype (-5.2 + 1.9j) <br/> displaynumtype ('aaa ') <br/>####### <br/> # output <br/>####### <br/>-69 is a number of type: int <br/> 99999999999999999999 is a number of type: Long <br/> 99999999999999999999 is a number of type: Long <br/> 98.6 is a number of Ty PE: Float <br/> (-5.2 + 1.9j) is a number of type: complex <br/> AAA is not a number at all! <Br/>
[2] Calling type twice
#! /Usr/bin/ENV <br/> python <br/> ''' typechk. PY ''' <br/> def displaynumtype (Num): <br/> Print num, 'is ', <br/> If type (Num) = type (0): <br/> Print 'an integer '<br/> Elif type (Num) = type (0l ): <br/> Print 'a long' <br/> Elif type (Num) = type (0.0 ): <br/> Print 'a float' <br/> Elif type (Num) = type (0 + 0j ): <br/> Print 'a complex number' <br/> else: <br/> Print 'not a number at all! '<Br/> displaynumtype (-69) <br/> displaynumtype (99999999999999999999l) <br/> displaynumtype (99999999999999999999) <br/> displaynumtype (98.6) <br/> displaynumtype (-5.2 + 1.9j) <br/> displaynumtype ('aaa ') <br/>####### <br/> # output <br/>####### <br/>-69 is an integer <br/> 99999999999999999999 is a long <br/> 99999999999999999999 is a long <br/> 98.6 is a float <br/> (-5.2 + 1.9j) is a complex number <br/> AAA is Not a number at all! <Br/>
[3] import types
#! /Usr/bin/ENV <br/> python <br/> Import types <br/> '''typechk. PY ''' <br/> def displaynumtype (Num): <br/> Print num, 'is ', <br/> If type (Num) = types. inttype: <br/> Print 'an integer '<br/> Elif type (Num) = types. longtype: <br/> Print 'a long' <br/> Elif type (Num) = types. floattype: <br/> Print 'a float' <br/> Elif type (Num) = types. complextype: <br/> Print 'a complex number' <br/> else: <br/> Print 'not Number at all! ', </P> <p> Print' but, it is ', <br/> If type (Num) = types. stringtype: <br/> Print 'a string' </P> <p> displaynumtype (-69) <br/> displaynumtype (99999999999999999999l) <br/> displaynumtype (99999999999999999999) <br/> displaynumtype (98.6) <br/> displaynumtype (-5.2 + 1.9j) <br/> displaynumtype ('aaa ') <br/>####### <br/> # output <br/>####### <br/>-69 is an integer <br/> 99999999999999999999 is a long <br/> 99999999999 999999999 is a long <br/> 98.6 is a float <br/> (-5.2 + 1.9j) is a complex number <br/> AAA is not a number at all! But, it is a string <br/>