
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
Example
Input : 200.040.009.400 Output : 200.40.9.400
Algorithm
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))
Output
Enter the IP address ::>200.006.020.900 New Ip Address ::> 200.6.20.900
- Related Articles
- Python program to remove leading zeros from an IP address
- C Program to validate an IP address
- Defanging an IP Address in Python
- Python program to Display Hostname and IP address?
- How to hide an IP address
- Python program to find the IP Address of the client
- How to get a Docker container's IP address from the host?
- JavaScript program to retrieve clients IP address
- Validate IP Address in Python
- How to generate IP addresses from a CIDR address using Python?
- How to get the Android Emulator's IP address?
- Program to display hostname and IP address C
- C# program to Display Hostname and IP address
- C Program to display hostname and IP address
- Java program to display Hostname and IP address

Advertisements