[Tutor] Getting the type of a variable
Etrade Griffiths
etrade.griffiths at dsl.pipex.com
Fri Oct 27 16:24:29 CEST 2006
Thanks, guys - like so many things, easy when you know how!
Alun Griffiths
At 14:27 27/10/2006, you wrote:
>Use this:
>
>if type(a) == type(1):
> print "a is int %d"
>elif type(a) == type(1.1):
> .......
>
>HTH..
>Regards,
>Asrarahmed Kadri
>
>
>
>On 10/27/06, Etrade Griffiths
><<mailto:etrade.griffiths at dsl.pipex.com>etrade.griffiths at dsl.pipex.com> wrote:
>Hi
>
>I want to check the type of a variable so that I know which format to use
>for printing eg
>
>def print_correct_format(a):
>
> if type(a) == 'int':
> print "a is an integer, value %i" % (a)
> elif type(a) == 'float':
> print "a is a float, value %f" % (a)
> else:
> print "a is unknown type"
>
>The comparison type(a) == 'int' etc does not work - I'm sure there's a
>simple way to fix this but can't see it at the moment - any suggestions?
>
>
>_______________________________________________
>Tutor maillist - <mailto:Tutor at python.org>Tutor at python.org
><http://mail.python.org/mailman/listinfo/tutor>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
>
>--
>To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061027/a1c8a15a/attachment.html
More information about the Tutor
mailing list