Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
closed by

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?

closed

4 Answers

0 votes
by (15.4k points)
selected by
 
Best answer
s = input('Type a word: ')

lowercase_letters = []

for char in s:

    if char.islower():

        lowercase_letters.append(char)

print("The lowercase letters found in the string are:", lowercase_letters)

Alternatively:

s = input('Type a word: ')

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

print("The lowercase letters in the string are:", lowercase_letters)

These code examples demonstrate how to detect lowercase letters in a string using the islower() method in Python. They prompt the user to input a word and then display the lowercase letters present in that word.
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...

0 votes
by (25.7k points)
In Python, you can use the islower() method to check whether a character is a lowercase letter. Here's an example:

s = input('Type a word: ')

lowercase_letters = []

for char in s:

    if char.islower():

        lowercase_letters.append(char)

print("Lowercase letters in the string:", lowercase_letters)

In the above code, the islower() method is used to check each character in the string s. If a character is a lowercase letter, it is added to the lowercase_letters list. Finally, the program prints the lowercase letters found in the string.

You can also achieve the same result using a list comprehension in a more concise way:

s = input('Type a word: ')

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

print("Lowercase letters in the string:", lowercase_letters)

Both examples will prompt you to enter a word and then display the lowercase letters present in that word.
0 votes
by (19k points)
s = input('Type a word: ')

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

print("Lowercase letters:", lowercase_letters)

This code efficiently detects lowercase letters in a string by using a list comprehension. It prompts the user to enter a word and then displays the lowercase letters found in that word.

Related questions

0 votes
1 answer
asked Jul 22, 2019 in Python by Sammy (47.6k points)
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...