I know about islower
and isupper
, but can you check whether or not that character is a letter?
For Example:
JavaScript
x
12
12
1
>>> s = 'abcdefg'
2
>>> s2 = '123abcd'
3
>>> s3 = 'abcDEFG'
4
>>> s[0].islower()
5
True
6
7
>>> s2[0].islower()
8
False
9
10
>>> s3[0].islower()
11
True
12
Is there any way to just ask if it is a character besides doing .islower()
or .isupper()
?
Advertisement
Answer
You can use str.isalpha()
.
For example:
JavaScript
1
5
1
s = 'a123b'
2
3
for char in s:
4
print(char, char.isalpha())
5
Output:
JavaScript
1
6
1
a True
2
1 False
3
2 False
4
3 False
5
b True
6