[Tutor] finding a non-letter?
Sean 'Shaleh' Perry
shalehperry@attbi.com
Wed, 2 Oct 2002 22:13:19 -0700
On Wednesday 02 October 2002 21:56, anthony polis wrote:
> hello,
>
> I need to know if a string's first charcter is an integer. How would I =
do
> this? I already know how to access the first character of a string by u=
sing
> str[0], but how would test to see if it's a non-letter?
>
import string
text =3D '1string'
if text[0] in string.digits:
print "text's first character is a number"
else:
print "or it is something else ...."
there is also the regex approach:
import re
text =3D '1string'
num_re =3D re.compile(r'^\d+')
if num_re.search(text):
print "text begins with a number"