def main():
port = 10000000
portChecked = portChecker(port)
if portChecked is portChecked:
print '%d is in the portlist' % port
def portChecker(x):
portCheck = range(65565)
portList = list(portCheck)
portCast = x
if portCast in portList:
return
else:
print '%d is not in the list' % portCast
if __name__ == '__main__':main()
开始学习Python,与暴力蟒蛇电子书,以为我会写一个简单的函数来检查正在由用户输入端口(或静态值)使用Python函数返回和比较
如果端口在该范围内,程序将打印出列表中的%d,但是就像这里一样,如果它在范围之外,那么两个打印语句都会执行。
我是否错过了函数调用,返回语句的使用或者我是否以错误的方式查看了这些内容。
谷歌搜索,似乎没有给出类似的解决方案,大多数教程使用int或字符串。
所有帮助表示赞赏。
'如果portChecked是portChecked:'永远是真正的 –
创建的65565个整数整个名单只是为了检查一个数字是否在一个区间是错误的。使用这个:'如果0