Method # 1: Using comprehension list + islower()
List comprehension and the islower function can be used to accomplish this specific task. List comprehension is mainly used to iterate over the list and check the islower function for lowercase characters.
# Python3 code to demonstrate how it works # Return lowercase characters in a string # Using comprehension list + islower () # initialization string test_str = "GeeksForGeeKs" # print the original line print ( "The original string is:" + str (test_str)) # Return lowercase characters in the string # Using comprehension list + islower () res = [char for char in test_str if char.islower ()] # print result print ( "The lowercase characters in string are:" + str (res)) |
Output:
The original string is: GeeksForGeeKs
The lowercase characters in string are: [’e’, ’e’, ’k’, ’s’, ’o’, ’r’, ’e’, ’e’, ’s’]
Method # 2: Using filter ()
+ lambda
The filter function along with the lambda functionality can be used to accomplish this particular task. The filter function does a specific case selection and the lambda function is used to traverse the line.
# Python3 code to demonstrate how it works # Return lowercase characters in a string # Using the () + lambda filter # initialization string test_str = "GeeksForGeeKs" # print original line print ( "The original string is:" + str (test_str)) # Return lowercase characters in a string # Using the () + lambda filter res = list ( filter ( lambda c: c.islower (), test_str)) # print result print ( " The lowercase characters in string are: " + str (res)) |
Output:
The original string is: GeeksForGeeKs
The lowercase characters in string are: [’e’, ’e’, ’k’, ’s’, ’o’, ’r’, ’e’, ’e’, ’s’]
Python | Return lowercase characters from a given string Python functions: Questions
Python | Return lowercase characters from a given string String Variables: Questions