Python程序从IP地址中删除前导0
IP地址已指定,我们的任务是从IP地址中删除前导零。首先,我们将给定的字符串除以“。”然后将其转换为整数,并删除前导零,然后将其连接回字符串。
示例
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
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短