[Tutor] simple question about numeric types

Emanuele Rocca ema at linux.it
Mon May 8 19:55:07 CEST 2006


Hello list,
I've got a question partially related to this thread.

* Gregor Lingl <glingl at aon.at>, [2006-05-03  0:24 +0200]:
>  v=<some numeric value>
>  if isinstance(v, int) or isinstance(v, float):
>       <block>

I wonder which is the recommended way to check the type of a value.

In other words, what should I choose between:
    isinstance(v, int)
    type(v) is int
    v.__class__ is int

There's simply more than one way to do it or some of them are
discouraged?

I've been told on #python that .__class__ is probably the worst one, but
without precise motivation, just as a personal opinion.

ciao,
    ema
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20060508/d37548be/attachment.pgp 


More information about the Tutor mailing list