[Tutor] checking if a variable is an integer?

Joel Goldstick joel.goldstick at gmail.com
Tue May 31 23:30:17 CEST 2011


On Tue, May 31, 2011 at 5:23 PM, Hans Barkei <handihans at gmail.com> wrote:

> I want to make  a program that finds all the prime numbers up to a number
> inputed by the user.
> I want to know if it is an integer because that will tell me if it is
> divisible by that number or not.
>                          *  ---------Hans-----*
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
http://stackoverflow.com/questions/1265665/python-check-if-a-string-represents-an-int-without-using-try-except

def RepresentsInt(s):
    try:
        int(s)
        return True
    except ValueError:
        return False

>>> print RepresentsInt("+123")
True
>>> print RepresentsInt("10.0")
False



-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110531/b10db459/attachment.html>


More information about the Tutor mailing list