[Tutor] simple question about numeric types

Chad Crabtree flaxeater at gmail.com
Tue May 9 00:15:02 CEST 2006


I think isinstance() is probably the best way to do this.  I however
always do type(x)==TestType:

where TestType is a string that is returned from type() or not what
ever the case.

On 5/8/06, Emanuele Rocca <ema at linux.it> wrote:
> 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
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.3 (GNU/Linux)
>
> iD8DBQFEX4X7C6DuA+rxm2ARAio8AJ9VWrIjlXL5bk43o0LwS1ZwPE3gZACdGTWI
> eIRPzxfs6KRpYc3bF2W4RwU=
> =Tmcs
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


More information about the Tutor mailing list