Change language

Python | Return lowercase characters from a given string

|

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

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method