O.rka O.rka - 1 year ago 128
Python Question

How to check if character in string is a letter? Python

So I know about islower and isupper, but i can't seem to find out if you can check whether or not that character is a letter?


s = 'abcdefg'
s2 = '123abcd'
s3 = 'abcDEFG'

s[0].islower() = True
s2[0].islower()= False

is there any way to just ask if it is a character besides doing .islower() or .isupper() ?

Answer Source

You can use isalpha(), see the docs at http://docs.python.org/2/library/stdtypes.html

An example:

>>> s = "a123b"
>>> for i in s:
...     print i, i.isalpha()
a True
1 False
2 False
3 False
b True
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download