Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.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()

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...