Python: Abbreviate 'Road' as 'Rd.' in a given string
Write a Python program to abbreviate 'Road' as 'Rd.' in a given string.
Sample Solution:
Python Code:
import re
street = '21 Ramkrishna Road'
print(re.sub('Road$', 'Rd.', street))
Sample Output:
21 Ramkrishna Rd.
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 separate and print the numbers and their position of a given string.
Next: Write a Python program to replace all occurrences of space, comma, or dot with a colon.
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