1. 程式人生 > 程式設計 >Python 實現try重新執行

Python 實現try重新執行

Python try重新執行:

def numberinput(): #建立方法
 try:
   s=int(input('number:'))
    return s
    print(a)
 except Exception as a:
   i=numberinput() #錯誤後重新呼叫方法
 print(i)
 return i

正確後會跳出迴圈,一直錯誤會進入死迴圈,不適合程式傳入引數

以上這篇Python 實現try重新執行就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。