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