Python program to remove leading 0's from an IP address

IP address is given bellow, our task is to remove leading zeroes from the IP address. First we split the given string by “.” and then convert it to an integer and removes the leading zeroes then join back them to a string.


Input :
Output :


Step 1: Input the IP address.
Step 2. Splits the ip by ".".
Step 3: Then convert the string to an integer we can use int (parameter) function.
Step 4: Removes the leading zeroes.
Step 5: Then convert it back to string by str (parameter) and then join them back by using join function.

Example Code

# Python program to remove leading zeros an IP address and print #the IP
# function to remove leading zeros
def IP(ip):
   zeroip = ".".join([str(int(i)) for i in ip.split(".")])
   return zeroip ;
   # Driver code
   ip =input("Enter the IP address ::>")
print("New Ip Address ::>",IP(ip))


Enter the IP address ::>
New Ip Address ::>
Vikyath Ram
Vikyath Ram

A born rival