Python脚本问题 [英] Problem with Python script
本文介绍了Python脚本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何验证1pv4的IP地址(4位数ip,如10.10.10.10)
如果我只给10.12.13而且没有ip地址。
我尝试过的事情:
How to validate the IP address for 1pv4(4 digit ip like 10.10.10.10)
if i gave 10.12.13 only and also no ip address .
What I have tried:
a = element.split('.')
if len(a) != 4:
return False
for x in a:
if not x.isdigit() or x == '':
return False
i = int(x)
if i < 0 or i > 255:
return False
return True
推荐答案
尝试:
Try:
def iptest(element):
a = element.split('.')
if len(a) != 4:
return False
for x in a:
if not x.isdigit() or x == '':
return False
i = int(x)
if i < 0 or i > 255:
return False
return True
这篇关于Python脚本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文