Remove leading zeros from an IP address
Write a Python program to remove leading zeros from each part of an IP address.
"289.03.02.054"
289.3.2.54
Approach
- Split on dots, convert each part to int and back.
Solution
ip = "289.03.02.054"print(".".join(str(int(part)) for part in ip.split(".")))289.3.2.54
Line by line
int("054") is 54, which drops the zeros; int("0") stays 0.
Learn the concept
New to this topic? Read the lesson, then come back.