Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k 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()

True

>>> s2[0].islower()

False

>>> s3[0].islower()

True

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

1 Answer

0 votes
by (26.4k points)

You can use a function, str.isalpha()

Example:

s = 'a123b'

for char in s:

    print(char, char.isalpha())

Output:

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!

28.4k questions

29.7k answers

500 comments

94.6k users

Browse Categories

...