Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I need to know whether there is a function that identifies the lowercase letters in a string. Let's assume I began composing this program: 

s=input('Type a word')

Would there be a capacity (function) that allows me to recognize a lowercase letter inside the string s?

Can anyone tell me, How to detect the lowercase letters in Python?

1 Answer

0 votes
by (26.4k points)

If you want to check if a character is a lower case, utilize the islower technique for str. This basic program prints every one of the lowercase letters in your string: 

for c in s:

    if c.islower():

         print c

Note that in Python 3 you should utilize print(c) rather than print c.

I also suggest you to utilize a list comprehension:

>>> s = 'abCd'

>>> lowercase_letters = [c for c in s if c.islower()]

>>> print lowercase_letters

['a', 'b', 'd']

You can also the join with a generator:

>>> lowercase_letters = ''.join(c for c in s if c.islower())

>>> print lowercase_letters

'abd'

Interested to learn the concepts of Python in detail? Come and join the python course to gain more knowledge in Python

Watch this video tutorial for more details...

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
0 votes
2 answers
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

...