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))

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



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program