On Dec 12, 10:59 pm, "Zero Piraeus" <[EMAIL PROTECTED]> wrote: > : > > > [...] IMHO regular > > expressions are overkill for the task you describe. You may be better > > served to > > just try to convert it to whatever number you want. > > > try: > > value=int(string1) > > Fails for the OP's example: > > >>> string1 = "ABC 11" > >>> int(string1) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ValueError: invalid literal for int(): ABC 11 > > > Or use string methods: > > > if string1.isdigit(): > > print "digits found" > > else: > > print "alphas found" > > Again ... > > >>> string1.isdigit() > False > > If you were desperate to avoid regexes, this works: > > >>> max([(d in string1) for d in "0123456789"]) > True > > ... but it's not exactly legible. >
How about: >>> string1 = "ABC 11" >>> any(c.isdigit() for c in string1) True -- http://mail.python.org/mailman/listinfo/python-list