前面的大哥写得挺好的,就是漏了点 像1.1.1. 3eGF之类的 我给大哥补上

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 验证IP地址
# @param IP string字符串 一个IP地址字符串
# @return string字符串
#
class Solution:
    def solve(self , IP: str) -> str:
        num = 0
        if '.' in IP:
            for ip in IP.split('.'):
                print(ip)
                if (ip.isdigit() is False) or ip == "" or ip[0] == '0' or (not 0<= int(ip) <=255) or IP[-1]=='.':
                    return 'Neither'
            return 'IPv4'
        if ':' in IP:
            for ip in IP.split(":"):
                if ip == "" or (len(ip)>1 and len(ip) == ip.count('0')) or len(ip)>4 or IP[-1]==":":
                    return 'Neither'
                try:
                    int(ip,16)
                except:
                    return 'Neither'
        return 'IPv6'
        # write code here