Python: Separate and print the numbers of a given string
Python Regular Expression: Exercise-27 with Solution
Write a Python program to separate and print the numbers in a given string.
Sample Solution:
Python Code:
import re
# Sample string.
text = "Ten 10, Twenty 20, Thirty 30"
result = re.split("\D+", text)
# Print results.
for element in result:
print(element)
Sample Output:
10 20 30
Pictorial Presentation:
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to match if two words from a list of words starting with letter 'P'.
Next: Write a Python program to find all words starting with 'a' or 'e' in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/re/python-re-exercise-27.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics