IP 주소는 다음과 같습니다. 우리의 임무는 IP 주소에서 선행 0을 제거하는 것입니다. 먼저 주어진 문자열을 "."로 나눕니다. 그런 다음 정수로 변환하고 선행 0을 제거한 다음 다시 문자열로 결합합니다.
예시
Input : 200.040.009.400 Output : 200.40.9.400
알고리즘
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.
예시 코드
# 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 ::>200.006.020.900 New Ip Address ::> 200.6.20.900