0 votes
1 view
in Python by (9.4k points)
edited by

I know what us islower and isupper, but how can we check whether a character in a string is a letter?Example:

>>> s = 'abcdefg'

>>> s2 = '123abcd'

>>> s3 = 'abcDEFG'

>>> s[0].islower()


>>> s2[0].islower()


>>> s3[0].islower()


Is there any way to check without using .islower() or .isupper()?

1 Answer

0 votes
by (19.4k points)

You can use a function, str.isalpha()


s = 'a123b'

for char in s:

    print(char, char.isalpha())


a  True

1  False

2  False

3  False

b  True

Wanna become a Python Expert? Come, and join: Python online course

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !