[Newbie]: How to find a specified digit in a number?

Scott David Daniels Scott.Daniels at Acm.Org
Wed Nov 10 13:20:42 EST 2004


Thomas Guettler wrote:
> Or you want to search in the string for e.g. "5":
> 
> mystring="12345"
> idx=mystring.find("3")
> if idx==-1:
>     print "not found"
> else:
>     print "Found it at index %s" % idx
> 
Actually, this should be written:

     mystring="12345"
     try:
         print "Found it at index %s" % mystring.index('3')
     except ValueError:
         print "not found"


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list