
需求: 接受一个来自外部的输入,并判断输入的字符串是否符合IP地址的条件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
import re import urllib from urllib import request ip_input = input('Please input a number') li = [3, 4, 5, 6, 7] print(li) p = re.compile('^((25[0-5]|2[0-4]d|[01]?dd?).){3}(25[0-5]|2[0-4]d|[01]?dd?)$') if (p.match(ip_input) != None): print('This is an IP address') else: print('It's not an Ip address)
|
近期评论