w3resource logo
Python Exercises

Python: Abbreviate 'Road' as 'Rd.' in a given string

Python Regular Expression: Exercise-30 with Solution

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.  

Python Code Editor:

import re
street = '21 Ramkrishna Road'
print(re.sub('Road$', 'Rd.', street))

Improve this sample solution and post your code through Disqus