In this program, we will take a string of IP address as input and remove zeros from an IP address.
Steps to solve the program
- Take a string of an IP address as input.
- Import re library.
- Remove zeros from the IP address using re.sub().
- Print the output.
#Importing re
import re
#Input string
str1 = "289.03.02.054"
string = re.sub('\.[0]*', '.', str1)
#Printing output
print(string)
Output :
289.3.2.54