Dumb python questions
Gerson Kurz
gerson.kurz at t-online.de
Wed Aug 15 04:30:31 EDT 2001
On 14 Aug 2001 22:59:05 -0700, Paul Rubin <phr-n2001 at nightsong.com>
wrote:
>2) Is there a way I can tell if a value is of an integer type? That is,
> I want to write a function is_int(x) so that
> is_int(3) = 1 # 3 is an integer type
> is_int(3L) = 1 # 3L is an integer type
> is_int(3.0) = 0 # 3.0 is float type
> is_int(3+2j) = 0 # 3+2j is complex type
>
some people already pointed out you can use type or isinstance; here
is a very nice function that works with your example (and shows of
python tricks):
is_int = lambda x: type(x) in [type(1),type(1L)]
More information about the Python-list
mailing list