python判断是否是合法的ip地址
def ip_fun(ip_str: str):
ip_list = ip_str.split(".")
flag = True
for ip in ip_list:
if ip.isdigit() and len(ip_list) == 4 and 0 <= int(ip) <= 255:
continue
else:
flag = False
break
if flag:
print("是ip地址")
return
print("不是ip地址")
ip_fun('172.0.0.256')