belongs to collection: Python String Exercises
Given:
str1 = 'I am 25 years and 10 months old'
Expected Output:
2510
Hint:
Use the string function isdigit()
isdigit()
Solution:
str1 = 'I am 25 years and 10 months old' print("Original string is", str1) # Retain Numbers in String # Using list comprehension + join() + isdigit() res = "".join([item for item in str1 if item.isdigit()]) print(res)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
Use the string function
isdigit()
Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer