isNumber? check

John Roth newsgroups at jhrothjr.com
Mon Sep 29 18:18:40 EDT 2003


"Rob Hunter" <rob at cs.brown.edu> wrote in message
news:mailman.1064867377.30354.python-list at python.org...
>
> On Monday, September 29, 2003, at 10:20 AM, Gerrit Holl wrote:
>
> > Rob Hunter wrote:
> >> How do I check if a value is a number in Python?
> >>
> >> One way is (x == type(1)) and (x == type(1.2)) and (x ==
> >> type(2387482734274)) and ...
> >>
> >> but this seems kludgy.  Any better way?
> >
> > Why do you want to do so?
>
>
> I am writing an interpreter, and my parser has to decide if an
> expression is a number or not.

You can always use eval() and see what it returns.

John Roth






More information about the Python-list mailing list