Python: Replace whitespaces with an underscore and vice versa
Write a Python program to replace whitespaces with an underscore and vice versa.
Sample Solution:
Python Code:
import re
text = 'Python Exercises'
text =text.replace (" ", "_")
print(text)
text =text.replace ("_", " ")
print(text)
Sample Output:
Python_Exercises Python Exercises
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 find the occurrence and position of the substrings within a string.
Next: Write a Python program to extract year, month and date from a an url.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics