[Python-talk] Does a string contain an integer

Cole Tuininga colet at code-energy.com
Thu Mar 27 19:36:05 EDT 2008


Hey folks - quick Python question.  I'm looking for an elegant way to
tell if a string is comprised of just an integer.  That is, if the
string is simply an integer.  In perl, I would just use a regex like
this:

if ($var =~ /^\d+$/) ...

I could use a regex to do this in Python, but is there a simpler and/or
more elegant way to do it?

-- 
A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
>> A: Top-posting.        
>>> Q: What is the most annoying thing on Usenet and in e-mail?

Cole Tuininga
colet at code-energy.com
http://www.code-energy.com/




More information about the Python-talk mailing list