Python else 關鍵字
定義和用法
else 關鍵字在條件語句(if 語句)中使用,它會在條件為 False 時決定做什么。
else 關鍵字也可以用于 try...except 代碼塊中,請看下面的例子。
更多實例
實例
在 try ... except 塊中使用 else 關鍵字定義未引發錯誤時的處理方法:
x = 5 try: x > 10 except: print("Something went wrong") else: print("The 'Try' code was executed without raising any errors!")